Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- using namespace std;
- int charToNum(char c)
- {
- return int(c) - 97;
- }
- int main()
- {
- setlocale(0, "RUS");
- string M;
- cout << "Введите открытый текст: " << endl;
- cin >> M;
- int L = M.length();
- string grnk;
- cout << "Введите ключ: " << endl;
- cin >> grnk;
- string grnk2 = grnk;
- cout << "Шифр Гронсфельда: " << endl;
- cout << "K=" << grnk << endl;
- for (int i = grnk.length(); i<M.length(); i++)
- grnk2 += grnk[i%grnk.length()];
- cout << "K=" << grnk2 << endl;
- for (int i = 0; i<L; i++) {
- if (M[i] >= 97 && M[i] <= 122)
- cout << M[i] << "=" << charToNum(M[i]) << "+" << grnk2[i] << "=" << char(97 + (charToNum(M[i]) + grnk2[i]) % 26) << endl;
- else
- cout << M[i] << ":" << "C[" << i << "]=" << M[i] << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement