Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void encode(string key, string file)
- {
- ifstream cin(file);
- ofstream cout("DC.txt");
- char c;
- int i = 0;
- while (!cin.eof())
- {
- c = cin.get();
- if (c != -1)
- {
- int tmp = c, help = key[i % key.length()];
- cout << char(tmp ^ help);
- }
- i++;
- }
- cin.close();
- cout.close();
- }
- void code(string key, string file)
- {
- ifstream cin(file);
- ofstream cout("CD.txt");
- char c;
- int i = 0;
- while (!cin.eof())
- {
- c = cin.get();
- if (c != -1)
- {
- int tmp = c, help = key[i % key.length()];
- cout << char(tmp ^ help);
- }
- i++;
- }
- cin.close();
- cout.close();
- }
- int main()
- {
- //setlocale(LC_ALL, "Russian");
- //char q = 'я'; cout << int(q);
- cout << "Sorry, but you can use this programm, if your code/encode file doesn't have Russian symbols.\nChoose the programm mode:\nWrite 1 if you need to encode file. Write 2 if you need to code file: ";
- int choice;
- cin >> choice;
- if (choice == 1)
- {
- string file, key;
- cout << "Write the name(with file extension) of file, which you need to encode: ";
- cin >> file;
- cout << "Write the key of code: ";
- cin >> key;
- encode(key, file);
- cout << "Decode file is DC.txt\n";
- }
- else
- {
- if (choice == 2)
- {
- string file, key;
- cout << "Write the name(with file extension) of file, which you need to code: ";
- cin >> file;
- cout << "Write the key of code: ";
- cin >> key;
- encode(key, file);
- cout << "Code file is CD.txt\n";
- }
- }
- cout << "My English is very well!!!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement