#include <iostream> #include <fstream> #include <string> #include <vector> #include…
- User
#include #include #include #include #include #include #include #include #include
std::string vigenere_decrypt(const std::string& ciphertext, const std::string& key, bool is_russian) { std::string decrypted_text; int key_length = key.length(); std::string upper_key = key; std::transform(upper_key.begin(), upper_key.end(), upper_key.begin(), ::toupper);
for (size_t i = 0; i < ciphertext.length(); ++i) { char char_upper = std::toupper(ciphertext[i]); if (is_russian ? (char_upper >= 'А' && char_upper <= 'Я') : (char_upper >= 'A' && char_upper <= 'Z')) { char key_char = upper_key[i % key_length]; int key_shift = is_russian ? (key_char - 'А') : (key_char - 'A'); char decrypted_char = is_russian ? (char_upper - 'А' - key_shift + 32) % 32 + 'А' : ((char_upper - 'A' - key_shift + 26) % 26 + 'A'); decrypted_text.push_back(decrypted_char); } else { decrypted_text.push_back(ciphertext[i]); } } return decrypted_text;}
std::string vigenere_encrypt(const std::string& plain_text, const std::string& key, bool is_russian) { std::string encrypted_text; int key_length = key.length(); std::string upper_key = key; std::transform(upper_key.begin(), upper_key.end(), upper_key.begin(), ::toupper); std::string alphabet = is_russian ? "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (size_t i = 0; i < plain_text.length(); ++i) { char char_upper = std::toupper(plain_text[i]); size_t pos = alphabet.find(char_upper); if (pos != std::string::npos) { char key_char = upper_key[i % key_length]; size_t shift = alphabet.find(std::toupper(key_char)); size_t encrypted_pos = (pos + shift) % alphabet.length(); char encrypted_char = alphabet[encrypted_pos]; if (std::islower(plain_text[i])) { encrypted_char = std::tolower(encrypted_char); } encrypted_text.push_back(encrypted_char); } else { encrypted_text.push_back(plain_text[i]); } } return encrypted_text;}
std::string read_file(const std::string& filename) { if (!std::filesystem::exists(filename)) { throw std::runtime_error("Ошибка: файл не может быть открыт."); } std::ifstream file(filename); std::string content((std::istreambuf_iterator(file)), (std::istreambuf_iterator())); return content; }
void write_file(const std::string& filename, const std::string& content) { std::ofstream file(filename); file << content; }
std::string clean_key(const std::string& key) { std::string cleaned_key; for (char c : key) { if ((c >= 'А' && c <= 'Я') || (c >= 'а' && c <= 'я') || (c >= 'A' && c <= 'Z')) { cleaned_key.push_back(c); } } return cleaned_key; }
std::string prepare_text(const std::string& text, bool is_russian) { std::string prepared_text; for (char c : text) { if ((is_russian && c >= 'А' && c <= 'Я') || (!is_russian && c >= 'A' && c <= 'Z')) { prepared_text.push_back(std::toupper(c)); } } return prepared_text; }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.