Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- //Объявляем массив символов русского и английского алфавита
- string alpha = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя,-.";
- int code(char str)
- {
- for (int i = 0; i < 33; i++) {
- if (str == alpha[i])
- return i;
- }
- }
- unsigned short lfsr = 0xACE1u;
- unsigned bit;
- unsigned period = 0;
- int main() {
- system("chcp 1251");
- system("cls");
- setlocale(LC_ALL, "Russian");
- ifstream start("start.txt");
- ofstream output("out.txt");
- char alphaB[30][2] = { ' ' };
- string message;
- int keym[10];
- string keybuf;
- string key;
- getline(start, key);
- getline(start, message);
- cout << endl;
- int o;
- int ukazi = 0;
- int ukazj = 0;
- //for (int i = 0; i < 100000; ++i)
- //cout << <<endl;
- uint16_t start_state = 0xACE1u; /* Any nonzero start state will work. */
- uint16_t lfsr = 1;
- while (!key.empty()) {
- lfsr*=code(key[0]);
- key.erase(0,1);
- }
- uint16_t bit; /* Must be 16bit to allow bit<<15 later in the code */
- for (int i = 0; i < 10; ++i)
- {
- while (lfsr != rand()) {
- bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1;
- lfsr = (lfsr >> 1) | (bit << 15);
- ++period;
- }
- cout << period%33<<endl;
- keym[i] = period % 33;
- }
- string decode;
- for (int i = 0; i < message.length(); ++i) {
- char buf = (message[i] ^ keym[i%10]);
- output << buf << ' ';
- decode += buf;
- }
- cout << endl << decode<<endl;
- for (int i = 0; i < decode.length(); ++i) {
- char buf = (decode[i] ^ keym[i%10]);
- cout << buf ;
- }
- cout << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment