Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <sstream>
- #include "tools.h"
- class Processor {
- private:
- public:
- std::string encode(std::string msg, std::string key);
- };
- std::string Processor::encode(std::string msg, std::string key) {
- std::bitset<64> N;
- for (int i = 0; i < 8; i++) {
- N <<= 8;
- N |= msg[i];
- }
- std::vector<std::bitset<16> > sub_blocks = Tools::subbgen(N);
- std::bitset<128> key128;
- for (int i = 0; i < 16; i++) {
- key128 <<= 8;
- key128 |= key[i];
- }
- std::vector<std::bitset<16> > K_array = Tools::keygen(key128);
- std::bitset<16> KS0, KS1, KS2, KS3, KF0, KF1, KF2, KF3;
- KS0 = K_array[4]; KS1 = K_array[5]; KS2 = K_array[6]; KS3 = K_array[7];
- KF0 = K_array[3]; KF1 = K_array[2]; KF2 = K_array[1]; KF3 = K_array[0];
- std::bitset<16> A,B,C,D;
- A = (sub_blocks[0] ^ KS0);
- B = (sub_blocks[1] ^ KS1);
- C = (sub_blocks[2] ^ KS2);
- D = (sub_blocks[3] ^ KS3);
- // 9 Раундов по 4 итерации каждый
- for (int i = 0; i < 9; i++) {
- for (int k = 0; k < 4; k++){
- std::bitset<16> KR = K_array[i];
- std::bitset<16> c = Table_C[i][k];
- std::bitset<16> KRC = Tools::bitsetAdd(KR, c);
- std::vector<std::bitset<16> > Y;
- switch (k) {
- case 0:
- Y = Tools::iteration(A,B,C,D,KRC,i,k);
- A = Y[0]; B = Y[1]; C = Y[2]; D = Y[3];
- break;
- case 1:
- Y = Tools::iteration(B,C,D,A,KRC,i,k);
- A = Y[0]; B = Y[1]; C = Y[2]; D = Y[3];
- break;
- case 2:
- Y = Tools::iteration(C,D,A,B,KRC,i,k);
- A = Y[0]; B = Y[1]; C = Y[2]; D = Y[3];
- break;
- case 3:
- Y = Tools::iteration(D,A,B,C,KRC,i,k);
- A = Y[0]; B = Y[1]; C = Y[2]; D = Y[3];
- break;
- }
- }
- }
- A ^= KF0; B ^= KF1; C ^= KF2; D ^= KF3;
- std::vector<std::bitset<8> > bit_result = Tools::resultcompiler(A,B,C,D);
- std::string total_result = "";
- for (int i = 0; i < bit_result.size(); i++) {
- std::stringstream ss;
- ss << std::hex << bit_result[i].to_ulong();
- total_result += ss.str() + " ";
- }
- return total_result;
- }
- int main(int argc, char const *argv[]) {
- Processor NUSH;
- std::string msg, key, result;
- msg = "valorant";
- key = "superdupersecret";
- result = NUSH.encode(msg, key);
- std::cout << result << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement