Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include "feistel.h"
- std::string GetFileName()
- {
- std::string bufferString;
- std::cout << "Enter name of file: ";
- std::cin >> bufferString;
- return bufferString;
- }
- std::vector<uint8_t> ReadFile()
- {
- std::vector<uint8_t> plainText;
- std::ifstream fileStream(GetFileName(), std::ios::binary);
- if (!fileStream)
- {
- std::cout << "Wrong file" << std::endl;
- return plainText;
- }
- fileStream.seekg(0, std::ios::end);
- plainText.reserve(fileStream.tellg());
- fileStream.seekg(0, std::ios::beg);
- for (size_t i = 0; i < plainText.capacity(); ++i)
- {
- unsigned char sym;
- fileStream >> sym;
- plainText.push_back(sym);
- }
- fileStream.close();
- return plainText;
- }
- void WriteResult(std::vector<uint8_t> result)
- {
- std::cout << "Result file" << std::endl;
- std::vector<uint8_t> data;
- std::ofstream fileStream(GetFileName(), std::ios::binary);
- if (fileStream.is_open())
- {
- for (auto& sym : result)
- {
- fileStream << sym;
- }
- }
- fileStream.close();
- }
- int main()
- {
- std::vector<uint8_t> synchroPackage;
- std::vector<uint8_t> sourceText;
- std::cout << "SynchroPackage" << std::endl;
- synchroPackage = ReadFile();
- std::cout << "Source text" << std::endl;
- sourceText = ReadFile();
- if (synchroPackage.empty() || sourceText.empty())
- {
- std::cout << "One of input files is empty" << std::endl;
- return 1;
- }
- if (synchroPackage.size() != 4)
- {
- std::cout << "SynchroPackage must be 4 symbols precisely" << std::endl;
- return 1;
- }
- std::cout << "Choose operation: " << std::endl;
- std::cout << "1 - Encryption" << std::endl;
- std::cout << "2 - Decryption" << std::endl << std::endl;
- std::cout << ">";
- size_t userChoice;
- std::cin >> userChoice;
- std::cin.ignore(32767, '\n');
- if (userChoice == 1)
- {
- WriteResult(feistel::OFB(synchroPackage, sourceText, feistel::ENCRYPT_OPER));
- }
- else if (userChoice == 2)
- {
- WriteResult(feistel::OFB(synchroPackage, sourceText, feistel::DECRYPT_OPER));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement