SHARE
TWEET

Untitled

a guest Sep 21st, 2017 152 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdint.h>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6.  
  7. #ifndef CRYPTOPP_ENABLE_NAMESPACE_WEAK
  8. #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
  9. #endif
  10.  
  11. #include <cryptopp\md5.h>
  12. #include <cryptopp\filters.h>
  13. #include <cryptopp\hex.h>
  14.  
  15. #pragma comment(lib, "cryptopp\\cryptlib_debug_dll")
  16.  
  17. uint8_t hash_table[256][256];
  18.  
  19. void initialize_hash_table()
  20. {
  21.     for (uint32_t i = 0; i < 256; i++)
  22.     {
  23.         for (uint32_t j = 0; j < 256; j++)
  24.         {
  25.             uint8_t key = 0;
  26.  
  27.             uint8_t column = i;
  28.             uint8_t row = j;
  29.  
  30.             while (column != 0 && row != 0)
  31.             {
  32.                 if (column & 1)
  33.                     key ^= row;
  34.                
  35.                 if (row & 0x80)
  36.                 {
  37.                     row *= 2;
  38.                     row ^= 0x2B;
  39.                 }
  40.                 else
  41.                 {
  42.                     row *= 2;
  43.                 }
  44.  
  45.                 column >>= 1;
  46.             }
  47.  
  48.             hash_table[i][j] = key;
  49.         }
  50.     }
  51. }
  52.  
  53. void generate_name_hash(std::string const& name, std::string& hash)
  54. {
  55.     hash.clear();
  56.  
  57.     uint8_t digest[CryptoPP::Weak::MD5::DIGESTSIZE];
  58.  
  59.     CryptoPP::Weak::MD5 md5;
  60.     md5.CalculateDigest(digest, reinterpret_cast<const uint8_t*>(name.c_str()), name.length());
  61.  
  62.     CryptoPP::HexEncoder encoder;
  63.     encoder.Attach(new CryptoPP::StringSink(hash));
  64.     encoder.Put(digest, sizeof(digest));
  65.     encoder.MessageEnd();
  66. }
  67.  
  68. void generate_name_checksum(std::string const& name, std::string& checksum)
  69. {
  70.     checksum.clear();
  71.    
  72.     int32_t key = 0;
  73.  
  74.     for (std::size_t i = 0; i < name.length(); i++)
  75.     {
  76.         uint8_t next = static_cast<uint8_t>(i + 1);
  77.  
  78.         int32_t xor_key = next ^ (name.at(i & 0xFF) + key);
  79.         int32_t xor_product = (xor_key ^ (next | 8)) + xor_key;
  80.  
  81.         key = std::abs(static_cast<int32_t>(std::pow(xor_product, 2))) % 0x1000;
  82.        
  83.         std::stringstream ss;
  84.         ss << std::hex << std::uppercase << key;
  85.         checksum.append(ss.str());
  86.     }
  87. }
  88.  
  89. void generate_serial_checksum(std::string const& serial, std::string& checksum)
  90. {
  91.     checksum.clear();
  92.  
  93.     for (std::size_t i = 0, offset = 0; i < serial.length(); i++)
  94.     {
  95.         if (i == 0)
  96.             checksum.push_back(static_cast<uint8_t>(std::stoul(serial.substr(i, 2), 0, 16)));
  97.         else if (serial.at(i) == ':')
  98.             checksum.push_back(static_cast<uint8_t>(std::stoul(serial.substr(i + 1, 2), 0, 16)));
  99.     }
  100. }
  101.  
  102. void generate_row_table(std::string const& name_checksum, uint8_t* row_table)
  103. {
  104.     uint8_t a = 0, b = 0, c = 0;
  105.  
  106.     for (uint32_t i = 0; i < 64; i++)
  107.     {
  108.         for (uint32_t j = 0; j < name_checksum.length(); j++)
  109.         {
  110.             c = b ^ name_checksum.at(j);
  111.             b = a ^ c ^ i ^ 2;
  112.             a = hash_table[c][b];
  113.             a ^= b ^ c ^ i;
  114.         }
  115.  
  116.         row_table[i] = a ^ b ^ c;
  117.     }
  118. }
  119.  
  120. void generate_product_table(std::string const& serial_checksum, uint8_t* product_table)
  121. {
  122.     product_table[5] = serial_checksum.at(0);
  123.     product_table[9] = serial_checksum.at(1);
  124.     product_table[1] = serial_checksum.at(2);
  125.     product_table[3] = serial_checksum.at(3);
  126.     product_table[15] = serial_checksum.at(4);
  127.     product_table[2] = serial_checksum.at(5);
  128.     product_table[8] = serial_checksum.at(6);
  129.     product_table[13] = serial_checksum.at(7);
  130.     product_table[4] = serial_checksum.at(8);
  131.     product_table[11] = serial_checksum.at(9);
  132.     product_table[6] = serial_checksum.at(10);
  133.     product_table[14] = serial_checksum.at(11);
  134.     product_table[7] = serial_checksum.at(12);
  135.     product_table[10] = serial_checksum.at(13);
  136.     product_table[0] = serial_checksum.at(14);
  137.     product_table[12] = serial_checksum.at(15);
  138.     product_table[26] = serial_checksum.at(16);
  139.     product_table[25] = serial_checksum.at(17);
  140.     product_table[17] = serial_checksum.at(18);
  141.     product_table[19] = serial_checksum.at(19);
  142.     product_table[31] = serial_checksum.at(20);
  143.     product_table[18] = serial_checksum.at(21);
  144.     product_table[24] = serial_checksum.at(22);
  145.     product_table[20] = serial_checksum.at(23);
  146.     product_table[29] = serial_checksum.at(24);
  147.     product_table[27] = serial_checksum.at(25);
  148.     product_table[30] = serial_checksum.at(26);
  149.     product_table[22] = serial_checksum.at(27);
  150.     product_table[23] = serial_checksum.at(28);
  151.     product_table[21] = serial_checksum.at(29);
  152.     product_table[16] = serial_checksum.at(30);
  153.     product_table[28] = serial_checksum.at(31);
  154. }
  155.  
  156. void generate_serial_hash(std::string const& serial_checksum, std::string const& name_checksum, std::string& hash)
  157. {
  158.     hash.clear();
  159.  
  160.     uint8_t row_table[64];
  161.     generate_row_table(name_checksum, row_table);
  162.  
  163.     uint8_t product_table[32];
  164.     generate_product_table(serial_checksum, product_table);
  165.  
  166.     for (uint32_t i = 0; i < 64; i++)
  167.     {
  168.         uint8_t key_table[16];
  169.  
  170.         for (uint32_t j = 0; j < 16; j++)
  171.         {
  172.             uint32_t key = hash_table[(product_table[16 + j] * 2) & 0xFF][row_table[i & 63]];
  173.  
  174.             if (j == 0)
  175.                 key_table[j] = key;
  176.             else
  177.             {
  178.                 key = hash_table[key][key_table[j - 1]];
  179.                 key_table[j] = key_table[j - 1] ^ key;
  180.             }
  181.         }
  182.        
  183.         uint8_t shuffle_table[16];
  184.  
  185.         for (uint32_t j = 0; j < 16; j++)
  186.             shuffle_table[j] = key_table[j] ^ product_table[j];
  187.  
  188.         memcpy(product_table, product_table + 16, 16);
  189.         memcpy(product_table + 16, shuffle_table, 16);
  190.     }
  191.  
  192.     hash.assign(product_table, product_table + 32);
  193. }
  194.  
  195. void generate_reverse_product_table(uint8_t* product_table, std::string& serial_checksum)
  196. {
  197.     serial_checksum.clear();
  198.     serial_checksum.push_back(product_table[5]);
  199.     serial_checksum.push_back(product_table[9]);
  200.     serial_checksum.push_back(product_table[1]);
  201.     serial_checksum.push_back(product_table[3]);
  202.     serial_checksum.push_back(product_table[15]);
  203.     serial_checksum.push_back(product_table[2]);
  204.     serial_checksum.push_back(product_table[8]);
  205.     serial_checksum.push_back(product_table[13]);
  206.     serial_checksum.push_back(product_table[4]);
  207.     serial_checksum.push_back(product_table[11]);
  208.     serial_checksum.push_back(product_table[6]);
  209.     serial_checksum.push_back(product_table[14]);
  210.     serial_checksum.push_back(product_table[7]);
  211.     serial_checksum.push_back(product_table[10]);
  212.     serial_checksum.push_back(product_table[0]);
  213.     serial_checksum.push_back(product_table[12]);
  214.     serial_checksum.push_back(product_table[26]);
  215.     serial_checksum.push_back(product_table[25]);
  216.     serial_checksum.push_back(product_table[17]);
  217.     serial_checksum.push_back(product_table[19]);
  218.     serial_checksum.push_back(product_table[31]);
  219.     serial_checksum.push_back(product_table[18]);
  220.     serial_checksum.push_back(product_table[24]);
  221.     serial_checksum.push_back(product_table[20]);
  222.     serial_checksum.push_back(product_table[29]);
  223.     serial_checksum.push_back(product_table[27]);
  224.     serial_checksum.push_back(product_table[30]);
  225.     serial_checksum.push_back(product_table[22]);
  226.     serial_checksum.push_back(product_table[23]);
  227.     serial_checksum.push_back(product_table[21]);
  228.     serial_checksum.push_back(product_table[16]);
  229.     serial_checksum.push_back(product_table[28]);
  230. }
  231.  
  232. void generate_serial(std::string const& name_hash, std::string const& name_checksum, std::string& serial_number)
  233. {
  234.     serial_number.clear();
  235.    
  236.     uint8_t row_table[64];
  237.     generate_row_table(name_checksum, row_table);
  238.  
  239.     uint8_t product_table[32];
  240.     memcpy(product_table, name_hash.data(), name_hash.size());
  241.  
  242.     for (uint32_t i = 64; i > 0; i--)
  243.     {
  244.         uint8_t shuffle_table[16];
  245.         memcpy(shuffle_table, product_table + 16, 16);
  246.         memcpy(product_table + 16, product_table, 16);
  247.    
  248.         uint8_t key_table[16];
  249.  
  250.         for (uint32_t j = 0; j < 16; j++)
  251.         {
  252.             uint32_t key = hash_table[(product_table[16 + j] * 2) & 0xFF][row_table[(i - 1) & 63]];
  253.  
  254.             if (j == 0)
  255.                 key_table[j] = key;
  256.             else
  257.             {
  258.                 key = hash_table[key][key_table[j - 1]];
  259.                 key_table[j] = key_table[j - 1] ^ key;
  260.             }
  261.         }
  262.    
  263.         for (uint32_t j = 0; j < 16; j++)
  264.             shuffle_table[j] ^= key_table[j];
  265.  
  266.         memcpy(product_table, shuffle_table, 16);
  267.     }
  268.    
  269.     std::string serial_checksum;
  270.     generate_reverse_product_table(product_table, serial_checksum);
  271.  
  272.     for (uint32_t i = 0; i < serial_checksum.size(); i++)
  273.     {
  274.         std::stringstream ss;
  275.         ss << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << (static_cast<uint32_t>(serial_checksum.at(i)) & 0xFF);
  276.        
  277.         serial_number.append(ss.str());
  278.  
  279.         if ((i + 1) != serial_checksum.size())
  280.             serial_number.push_back(':');
  281.     }
  282. }
  283.  
  284. bool evaluate_hashes(std::string const& serial_name_hash, std::string const& serial_hash)
  285. {
  286.     uint32_t equals = 0;
  287.  
  288.     for (uint32_t i = 0; i < 32; i++)
  289.     {
  290.         if (serial_hash.length() > i &&
  291.             serial_name_hash.length() > i &&
  292.             serial_hash.at(i) == serial_name_hash.at(i))
  293.         {
  294.             equals++;
  295.         }
  296.     }
  297.    
  298.     return (equals == 32);
  299. }
  300.  
  301. bool evaluate(std::string const& serial_name, std::string const& serial_number)
  302. {
  303.     if (!serial_name.empty() && !serial_number.empty())
  304.     {
  305.         /* Name */
  306.         std::string serial_name_hash;
  307.         generate_name_hash(serial_name, serial_name_hash);
  308.         std::cout << "Serial name hash:\t" << serial_name_hash << std::endl;
  309.  
  310.         std::string serial_name_checksum;
  311.         generate_name_checksum(serial_name, serial_name_checksum);
  312.         std::cout << "Serial name checksum:\t" << serial_name_checksum << std::endl;
  313.  
  314.         /* Serial */
  315.         std::string serial_checksum;
  316.         generate_serial_checksum(serial_number, serial_checksum);
  317.  
  318.         std::string serial_hash;
  319.         generate_serial_hash(serial_checksum, serial_name_checksum, serial_hash);
  320.  
  321.         /* Evaluation */
  322.         std::cout << std::endl;
  323.  
  324.         if (evaluate_hashes(serial_name_hash, serial_hash))
  325.             return true;
  326.     }
  327.  
  328.     return false;
  329. }
  330.  
  331. void generate(std::string const& serial_name)
  332. {
  333.     /* Name */
  334.     std::string serial_name_hash;
  335.     generate_name_hash(serial_name, serial_name_hash);
  336.  
  337.     std::string serial_name_checksum;
  338.     generate_name_checksum(serial_name, serial_name_checksum);
  339.    
  340.     /* Serial */
  341.     std::string serial_number;
  342.     generate_serial(serial_name_hash, serial_name_checksum, serial_number);
  343.  
  344.     if (evaluate(serial_name, serial_number))
  345.         std::cout << "Serial number:\t\t" << serial_number << std::endl;
  346. }
  347.  
  348. void perform_test()
  349. {
  350.     initialize_hash_table();
  351.    
  352.     std::string serial_name;
  353.     std::cout << "Enter serial name:\t";
  354.     std::getline(std::cin, serial_name);
  355.     std::cout << std::endl;
  356.  
  357.     generate(serial_name);
  358. }
  359.  
  360. #include <Windows.h>
  361.  
  362. int main()
  363. {
  364.     RECT desktop;
  365.     SystemParametersInfo(SPI_GETWORKAREA, 0, &desktop, 0);
  366.     MoveWindow(GetConsoleWindow(), 0, 0, 1000, (desktop.bottom - desktop.top), TRUE);
  367.    
  368.     perform_test();
  369.  
  370.     std::cin.ignore();
  371.     std::cin.get();
  372.     return 0;
  373. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top