Advertisement
Guest User

Key_Recover.cpp

a guest
Feb 17th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <shlwapi.h>
  4. #include <string>
  5.  
  6. #pragma comment( lib, "shlwapi.lib")
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12.     ifstream keyFile("key.dat", ios_base::binary);
  13.     string header = "";
  14.     string key = "";
  15.     if(!keyFile.is_open())
  16.         return 0;
  17.     getline(keyFile, header);
  18.     getline(keyFile, key);
  19.     keyFile.close();
  20.     char keyDat[18];
  21.     sprintf_s(keyDat, 18, "%s", key.c_str());
  22.     printf("Please input your plain-text key. DO NOT use dashes in this key. Make sure it is one word.\n");
  23.     char keyRaw[18];
  24.     gets_s(keyRaw, 18);
  25.     char keyDigest[18];
  26.     for(int i = 0; i < 18; i++)
  27.     {
  28.         keyDigest[i] = (char) keyDat[i] ^ keyRaw[i];
  29.     }
  30.     ifstream lostKeyFile("keyLost.dat", ios_base::binary);
  31.     getline(lostKeyFile, header);
  32.     key = "";
  33.     getline(lostKeyFile, key);
  34.     sprintf_s(keyDat, 18, "%s", key.c_str());
  35.     memset(keyRaw, 0x00, 18);
  36.     for(int i = 0; i < 18; i++)
  37.     {
  38.         keyRaw[i] = (char) keyDat[i] ^ keyDigest[i];
  39.     }
  40.     printf("Your recovered key is: %s\n", keyRaw);
  41.     keyFile.close();
  42.     printf("Press Enter to save this key to out.txt and close the program.");
  43.     cin.ignore();
  44.     ofstream outFile("out.txt");
  45.     outFile.write(keyRaw, 17);
  46.     outFile.close();
  47.     return 1;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement