Guest User

Untitled

a guest
Jun 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. char encrypt()
  6. {
  7.     cout << "Welcome to the amazing world of encrypting!\n" << "Please enter the text you want to encrypt: ";
  8.  
  9.     string input_text;
  10.     string encrypted_text;
  11.  
  12.     while (cin.get() != '\n'); getline(cin, input_text); cout << endl;
  13.  
  14.     int length = input_text.length();
  15.  
  16.  
  17.  
  18.     for(int i = 0; i < length; i++) // input_text[i]; to check the letter that's going through the for loop
  19.     {
  20.         int input_text_number = input_text[i];
  21.  
  22.         /*cout << input_text_number << " "; // This is a test for the number of the letter in the loop
  23.         */
  24.  
  25.         int encrypted_number = input_text_number + 1;
  26.  
  27.         encrypted_text = encrypted_number;
  28.  
  29.         cout << encrypted_text;
  30.     }
  31.  
  32.     cout << endl;
  33.     return 0;
  34. }
  35.  
  36. char decrypt()
  37. {
  38.     cout << "Welcome to the amazing world of decrypting!\n" << "Please enter the text you want to decrypt: ";
  39.  
  40.     string input_text_decrypted;
  41.     string decrypted_text;
  42.  
  43.     while (cin.get() != '\n'); getline(cin, input_text_decrypted); cout << endl;
  44.  
  45.     int length_decrypted = input_text_decrypted.length();
  46.  
  47.     for(int o = 0; o < length_decrypted; o++)
  48.     {
  49.         int input_text_decrypted_number = input_text_decrypted[o];
  50.  
  51.         int decrypted_number = input_text_decrypted_number - 1;
  52.  
  53.         decrypted_text = decrypted_number;
  54.        
  55.         cout << decrypted_text;
  56.     }
  57.  
  58.     cout << endl;
  59.     return 0;
  60. }
  61.  
  62.  
  63. int main()
  64. {
  65.  
  66.     system("TITLE Crypt-o-matic");
  67.  
  68.     int enc_or_dec;
  69.  
  70.     cout << "Welcome to the Crypt-o-matic! Would you like to encrypt (0), or decrypt(1)?" << endl;
  71.  
  72.     cin >> enc_or_dec;
  73.  
  74.     if(enc_or_dec == 0) // To encrypt
  75.     {
  76.         encrypt();
  77.     }
  78.  
  79.     if(enc_or_dec == 1) // To decrypt
  80.     {
  81.         decrypt();
  82.     }
  83.  
  84.    
  85.     system("PAUSE");
  86.     return 0;
  87. }
Add Comment
Please, Sign In to add comment