Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. void encryption(int key,char m[]);
  5. void decryption(int key,char m[]);
  6. int main()
  7. {
  8.     int key,v;
  9.     char *m = new char;
  10.     cout << "Key:"; cin >> key;
  11.     cout << "Text:";
  12.     cin.getline(m,sizeof(m));
  13.     cout << "1-encryption;2-decryption"; cin >> v;
  14.     switch (v)
  15.     {
  16.     case 1: encryption(key,m); break;
  17.     case 2: decryption(key,m); break;
  18.     }
  19.     delete[]m;
  20.     system("pause");
  21.     return 0;
  22. }
  23. void encryption(int key,char m[])
  24. {
  25.     for (int i = 0; i < '\0'; i++)
  26.     {
  27.         if ((m[i] >= 'A' && m[i] <= 'Z') || (m[i] >= 'a' && m[i] <= 'z'))
  28.         {
  29.             if (m[i] >= 'A' && m[i] <= 'Z')
  30.             {
  31.                 static_cast<int>(m[i]);
  32.                 m[i] = (m[i] + key + 41) % 26;
  33.                 static_cast<char>(m[i]);
  34.             }
  35.             else
  36.             {
  37.                 static_cast<int>(m[i]);
  38.                 m[i] = (m[i] + key + 61) % 26;
  39.                 static_cast<char>(m[i]);
  40.             }
  41.         }
  42.     }
  43.     cout << m << endl;
  44. }
  45. void decryption(int key,char m[])
  46. {
  47.     for (int i = 0; i < '\0'; i++)
  48.     {
  49.         if ((m[i] >= 'A' && m[i] <= 'Z') || (m[i] >= 'a' && m[i] <= 'z'))
  50.         {
  51.             if (m[i] >= 'A' && m[i] <= 'Z')
  52.             {
  53.                 static_cast<int>(m[i]);
  54.                 m[i] = (m[i] + key + 15) % 26;
  55.                 static_cast<char>(m[i]);
  56.             }
  57.             else
  58.             {
  59.                 static_cast<int>(m[i]);
  60.                 m[i] = (m[i] - key + 35) % 26;
  61.                 static_cast<char>(m[i]);
  62.             }
  63.         }
  64.     }
  65.     cout << m << endl;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement