Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <string>
- #include <io.h>
- #include <fcntl.h>
- using namespace std;
- const wstring source_characters = L"йцукенгшщзхъфывапролджэячсмитьбю1234567890ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ~`!@#$%^&*()_+-=\";:?{}[]\\|/'.,<> qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
- const wstring characters_set = L"qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM~`!@#$%^&*()_+-=\";:?{}[]\\|/'.,<>¡¢£¤¥¦§©®µ¼½DZƕƔƓƒƑƘƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǾǽǼǻȀȄȐ";
- wstring characters_encrypt(wstring characters_set);
- wstring input_string_encrypting(wstring input_message, wstring source_characters, wstring encrypted_characters);
- wstring input_string_decrypting(wstring input_message, wstring encrypted_characters, wstring encrypted_string);
- int main() {
- setlocale(LC_ALL, "");
- _setmode(_fileno(stdout), _O_U16TEXT);
- wstring encrypted_characters = characters_encrypt(characters_set);
- wstring input_message = L"Я помню чудное мгновенье: Передо мной явилась ты, Как мимолетное виденье, Как гений чистой красоты. В томленьях грусти безнадежной В тревогах шумной суеты, Звучал мне долго голос нежный И снились милые черты.";
- wstring encrypted_string = input_string_encrypting(input_message, source_characters, encrypted_characters);
- wstring decrypted_string = input_string_decrypting(input_message, encrypted_characters, encrypted_string);
- return 0;
- }
- wstring characters_encrypt(wstring characters_set)
- {
- int num;
- wstring encrypted_characters;
- bool duplicate;
- srand(time(NULL));
- wcout << characters_set << '\n';
- int used_numbers[200];
- for ( int i = 0; i < characters_set.size(); i++ )
- {
- num = 1 + rand() % characters_set.size() - 1;
- for ( int j = 0; j < i + 1; j++ )
- {
- if ( used_numbers[j] == num )
- {
- duplicate = true;
- i--;
- break;
- }
- duplicate = false;
- }
- if ( !duplicate )
- {
- used_numbers[i] = num;
- encrypted_characters += characters_set[num];
- }
- }
- wcout << encrypted_characters << '\n';
- return encrypted_characters;
- }
- wstring input_string_encrypting(wstring input_message, wstring source_characters, wstring encrypted_characters)
- {
- wstring encrypted_string;
- int char_pos;
- for ( int k = 0; k < input_message.size(); k++ )
- {
- char_pos = source_characters.find(input_message[k]);
- encrypted_string += encrypted_characters[char_pos];
- }
- wcout << '\n' << encrypted_string << '\n';
- return encrypted_string;
- }
- wstring input_string_decrypting(wstring input_message, wstring encrypted_characters, wstring encrypted_string)
- {
- wstring decrypted_string;
- int char_pos;
- for ( int k = 0; k < input_message.size(); k++ )
- {
- char_pos = encrypted_characters.find(encrypted_string[k]);
- decrypted_string += source_characters[char_pos];
- }
- wcout << '\n' << decrypted_string << '\n';
- return decrypted_string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement