Advertisement
ademosh

Untitled

Oct 21st, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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 alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя";
  12. int code(char s)
  13. {
  14. for (int i = 0; i < alpha.length(); i++) {
  15. if (s == alpha[i])
  16. return i;
  17. }
  18. }
  19. int main() {
  20. system("chcp 1251");
  21. system("cls");
  22. setlocale(LC_ALL, "Russian");
  23. ifstream ifst;
  24. ofstream ofst;
  25. string alphaB[33][33] = { "" };
  26. for (int i = 0; i < 33; ++i)
  27. {
  28. int j = 0;
  29. int shift = i;
  30. cout << shift << endl;
  31. while (j < 33)
  32. {
  33. if (shift == 33) shift -= 33;
  34. alphaB[i][j] = alpha[shift];
  35. shift++;
  36. j++;
  37. }
  38. }
  39. for (int i = 0; i < 33; ++i)
  40. {
  41. for (int j = 0; j < 33; ++j)
  42. cout << alphaB[i][j] << ' ';
  43. cout << endl;
  44. }
  45. string message = "стартовый";
  46. //string message = "НЮрйПлуаё";
  47. ofstream output("out.txt");
  48. cout << endl;
  49. int o=0;
  50. string key = "абвгд";
  51. if (o == 0)
  52. {
  53. int k = 0;
  54. int cod;
  55. int resultcode=0;
  56. string out;
  57. for (int i = 0; i < message.length(); i += 1)
  58. {
  59. if (k >= key.length())
  60. k = 0;
  61. k++;
  62.  
  63. resultcode += code(message[i]);
  64.  
  65. resultcode += code(key[k]);
  66. //if (resultcode >= 66) resultcode -= 33;
  67. //if (resultcode >= 66) resultcode -= 33;
  68. int stroka = abs(code(message[i])) ;
  69. int stolb = abs(key[k]) ;
  70. cout << message[i] << ' ' << stroka << ' '<< stolb<<' '<<endl;
  71. resultcode = 0;
  72. }
  73.  
  74.  
  75. }
  76. if (o == 1)
  77. {
  78. int k = 0;
  79. int cod;
  80. int resultcode = 0;
  81. string out;
  82. for (int i = 0; i < message.length(); i += 1)
  83. {
  84. if (k >= key.length())
  85. k = 0;
  86. k++;
  87.  
  88. resultcode += code(message[i]);
  89.  
  90. resultcode -= code(key[k]);
  91. if (resultcode <1) resultcode += 33;
  92. if (resultcode >= 66) resultcode -= 33;
  93. cout << message[i] << ' ' << alpha[resultcode] << ' ' << endl;
  94. resultcode = 0;
  95. }
  96.  
  97.  
  98. }
  99. system("pause");
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement