Advertisement
dimuster

caesar

Oct 10th, 2021
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. string getType(char s, string alphabet) {
  9.     if (s >= alphabet[0] && s <= alphabet[1]) {
  10.         return "low";
  11.     } else if (s >= alphabet[2] && s <= alphabet[3]) {
  12.         return "up";
  13.     }
  14.     return "none";
  15. }
  16.  
  17. void decode(string message, int index) {
  18.     vector<string> langs {"аяАЯ32", "azAZ26"};
  19.     string alphabet = langs[index].substr(0, 4);
  20.     int countLetters = stoi(langs[index].substr(4));
  21.     cout << "\nK0 " << message << "\n";
  22.     for (int i = 0; i < countLetters - 1; i++) {
  23.         for (int j = 0; j < message.size(); j++) {
  24.             string type = getType(message[j], alphabet);
  25.             if (type == "none") continue;
  26.             message[j] = char(char(message[j]) + 1);
  27.             if (getType(message[j], alphabet) != type) {
  28.                 message[j] = char(char(message[j]) - countLetters);
  29.             }
  30.         }
  31.         cout << "K" << i + 1 << " " << message << "\n";
  32.     }
  33.     return;
  34. }
  35.  
  36. int main() {
  37. //    SetConsoleCP(1251);
  38. //    SetConsoleOutputCP(1251);
  39.    
  40.     vector<string> langs {"ru", "eng"};
  41.     string message, lang;
  42. //    int numOfLang = -1;
  43.     int numOfLang = 1;
  44.    
  45.    
  46. //    cout << "Введите язык шифра ('ru'(w/o 'ё'), 'eng'): ";
  47. //    getline(cin, lang);
  48. //    
  49. //    
  50. //    for (int i = 0; i < langs.size(); i++) {
  51. //        if (langs[i] == lang) {
  52. //            numOfLang = i;
  53. //            break;
  54. //        }
  55. //    }
  56. //    if (!(numOfLang + 1)) {
  57. //        cout << "Язык не поддерживается!";
  58. //        return 0;
  59. //    }
  60.    
  61. //    cout << "Введите текст:\n";
  62.     cout << "Enter text: ";
  63.     getline(cin, message);
  64.    
  65.     decode(message, numOfLang);
  66.    
  67.     cout << "DONE.";
  68.    
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement