Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<cmath>
- using namespace std;
- void check()
- {
- }
- string Text()
- {
- string text;
- cout << "Enter the text: "; getline(cin, text);
- return text;
- }
- void Key()
- {
- int key;
- cout << "Enter the key: "; cin >> key;
- srand(key);
- }
- void XOR(string text, int gamma, int len)
- {
- int *faza = new int[len];
- int Gamma[2];
- int gammatemp = gamma;
- if (gamma < 256)
- {
- Gamma[0] = gamma;
- Gamma[1] = 0;
- }
- else
- {
- for (int i = 15; i > 7; i--)
- {
- if (gammatemp >= pow(2, i))
- gammatemp -= pow(2, i);
- }
- Gamma[0] = gammatemp;
- Gamma[1] = gamma - gammatemp;
- }
- // cout << gamma << " " << Gamma[0] << " " << Gamma[1];
- for (int i = 0; i < len; i++)
- {
- // cout << endl << /*text[i] - '0' << "\t" << */int(text[i]) - 48;
- faza[i] = (int(text[i]) - 48) ^ Gamma[i % 2];
- // cout << "\t" << faza[i] << char(faza[i]);
- }
- }
- void Encrypt(string text, int gamma, int len)
- {
- if (len % 2 != 0)
- text[len] = '0';
- /*string faza = */XOR(text, gamma, len);
- }
- void Decrypt(string text, int gamma, int len)
- }
- W processe
- }
- int main()
- {
- char choice;
- cout << "Encrypt(E) or Decrypt(D)? "; cin >> choice;
- cin.ignore();
- string text = Text();
- int len = text.length();
- Key();
- int gamma = rand();
- if (choice == 'E')
- {
- Encrypt(text, gamma, len);
- }
- else
- {
- if (choice == 'D')
- Decrypt(text, gamma, len);
- else
- cout << "Error 1\n";
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement