ademosh

5 ЗИ

Oct 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include "pch.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7.  
  8.  
  9. using namespace std;
  10. //Объявляем массив символов русского и английского алфавита
  11. string symbols = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
  12. int code(char s)
  13. {
  14. for (int i = 1; i <= symbols.length(); i++)
  15. if (s == symbols[i])
  16. return i;
  17. }
  18. int main() {
  19. system("chcp 1251");
  20. system("cls");
  21. setlocale(LC_ALL, "Russian");
  22. ifstream ifst;
  23. ofstream ofst;
  24. string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
  25. string key = "лежбище";
  26. //string message = "аааяяя";
  27. string message = "ежбЗШД";
  28. int o=1;
  29. if (o == 0)
  30. {
  31. int k = 0;
  32. int cod;
  33. int resultcode=0;
  34. string out;
  35. for (int i = 0; i < message.length(); i += 1)
  36. {
  37. if (k >= key.length())
  38. k = 0;
  39. k++;
  40.  
  41. resultcode += code(message[i]);
  42.  
  43. resultcode += code(key[k]);
  44. if (resultcode >= 66) resultcode -= 66;
  45. if (resultcode >= 66) resultcode -= 66;
  46. cout << message[i] << ' ' << alpha[resultcode]<< ' '<< resultcode<<endl;
  47. resultcode = 0;
  48. }
  49.  
  50.  
  51. }
  52. if (o == 1)
  53. {
  54. int k = 0;
  55. int cod;
  56. int resultcode = 0;
  57. string out;
  58. for (int i = 0; i < message.length(); i += 1)
  59. {
  60. if (k >= key.length())
  61. k = 0;
  62. k++;
  63.  
  64. resultcode += code(message[i]);
  65.  
  66. resultcode -= code(key[k]);
  67. if (resultcode <1) resultcode += 66;
  68. if (resultcode >= 66) resultcode -= 66;
  69. cout << message[i] << ' ' << alpha[resultcode] << ' ' << resultcode << endl;
  70. resultcode = 0;
  71. }
  72.  
  73.  
  74. }
  75. system("pause");
  76. return 0;
  77. }
Add Comment
Please, Sign In to add comment