Advertisement
Guest User

libraryf

a guest
May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int charToNum(char c)
  7.  
  8. {
  9.  
  10. return int(c) - 97;
  11.  
  12. }
  13.  
  14. int main()
  15. {
  16. setlocale(0, "RUS");
  17. string M;
  18. cout << "Введите открытый текст: " << endl;
  19. cin >> M;
  20. int L = M.length();
  21. string grnk;
  22. cout << "Введите ключ: " << endl;
  23. cin >> grnk;
  24. string grnk2 = grnk;
  25. cout << "Шифр Гронсфельда: " << endl;
  26. cout << "K=" << grnk << endl;
  27. for (int i = grnk.length(); i<M.length(); i++)
  28. grnk2 += grnk[i%grnk.length()];
  29. cout << "K=" << grnk2 << endl;
  30. for (int i = 0; i<L; i++) {
  31. if (M[i] >= 97 && M[i] <= 122)
  32. cout << M[i] << "=" << charToNum(M[i]) << "+" << grnk2[i] << "=" << char(97 + (charToNum(M[i]) + grnk2[i]) % 26) << endl;
  33. else
  34. cout << M[i] << ":" << "C[" << i << "]=" << M[i] << endl;
  35. }
  36. system("pause");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement