ademosh

6 безопасность

Oct 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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. ofstream output("out.txt");
  29. int o=1;
  30. if (o == 0)
  31. {
  32. int k = 0;
  33. int cod;
  34. int resultcode=0;
  35. string out;
  36. for (int i = 0; i < message.length(); i += 1)
  37. {
  38. if (k >= key.length())
  39. k = 0;
  40. k++;
  41.  
  42. resultcode += code(message[i]);
  43.  
  44. resultcode += code(key[k]);
  45. if (resultcode >= 66) resultcode -= 66;
  46. if (resultcode >= 66) resultcode -= 66;
  47. cout << message[i] << ' ' << alpha[resultcode]<< ' '<<endl;
  48. output << alpha[resultcode];
  49. resultcode = 0;
  50. }
  51.  
  52.  
  53. }
  54. if (o == 1)
  55. {
  56. int k = 0;
  57. int cod;
  58. int resultcode = 0;
  59. string out;
  60. for (int i = 0; i < message.length(); i += 1)
  61. {
  62. if (k >= key.length())
  63. k = 0;
  64. k++;
  65.  
  66. resultcode += code(message[i]);
  67.  
  68. resultcode -= code(key[k]);
  69. if (resultcode <1) resultcode += 66;
  70. if (resultcode >= 66) resultcode -= 66;
  71. cout << message[i] << ' ' << alpha[resultcode] << ' ' << endl;
  72. resultcode = 0;
  73. }
  74.  
  75.  
  76. }
  77. system("pause");
  78. return 0;
  79. }
Add Comment
Please, Sign In to add comment