Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Aceix::Code

By: aceix on Oct 18th, 2012  |  syntax: C++  |  size: 4.99 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef MAIN_H
  2. #define MAIN_H
  3.  
  4. void fnError(int nErrCode)
  5. {
  6.     cerr<<"\n\nError #"<<nErrCode<<" - Check help section for more information!";
  7. }
  8.  
  9. enum ERROR_CODES
  10. {
  11.     ERR_WRONGINPUT=101,ERR_ENCRYPTION=102,ERR_UNABLETOSAVE
  12. }error;
  13.  
  14. char progress[27]={'/','\\','!','@','#','$','%','&','*','+','~','<','>',
  15.                    '/','\\','!','@','#','$','%','&','*','+','~','<','>','\0'};
  16. fstream myFile;
  17.  
  18. void Menu()
  19. {
  20.     system("CLS");
  21.     cout<<"----------------------Welcome to Aceix Encryption Tool--------------------------";
  22.     cout<<setw(80)<<right<<"v1.0"<<endl<<endl;
  23. }
  24.  
  25. int fnMainMenu(int& iChoice)
  26. {
  27.     cout<<"Select what you want to do by typing the number..."<<endl<<endl;
  28.     cout<<"\t1. Encrypt a string."<<endl
  29.         <<"\t2. Decrypt a string."<<endl
  30.         <<"\t3. Goto: Help Section."<<endl
  31.         <<"\t4. Exit this app."<<flush;
  32.     cout<<"\n\n\tSelection: #";
  33.     cin>>iChoice;
  34.     if(cin.fail())
  35.     {
  36.         error=ERR_WRONGINPUT;
  37.         fnError(error);
  38.         cin.clear();
  39.         iChoice=0;
  40.         cin.ignore();
  41.     }
  42.  
  43.  
  44.     return iChoice;
  45. }
  46.  
  47. class encryptndecrypt
  48. {
  49.     protected:
  50.         string password;
  51.         string szEncryptedKey;
  52.         string szDecryptedKey;
  53.         string szMD5Key;
  54.     public:
  55.         encryptndecrypt()
  56.         {
  57.             string szEncryptedKey="";
  58.             string szDecryptedKey="";
  59.         }
  60.         int encrypt();
  61.         int decrypt();
  62.         void save();
  63.         void load();
  64.         void fnClearInstance();
  65.         bool fnSaveMD5ToClipboard();
  66.         void showMD5()
  67.         {
  68.             cout<<szMD5Key;
  69.         }
  70.     private:
  71.         int encrypt_now(string);
  72.         int decrypt_now(string);
  73. };
  74.  
  75. int encryptndecrypt::encrypt()
  76. {
  77.     char random;
  78.     srand(time(NULL));
  79.  
  80.     getline(cin,password);
  81.  
  82.     cout<<"\n\nPlease wait!\nEncrypting..."<<endl;
  83.     for(unsigned i=0;i<password.length();i++)
  84.     {
  85.         random=progress[rand()%25];
  86.         cout<<random;
  87.         Sleep(500);
  88.     }
  89.  
  90.     return (encrypt_now(password));
  91. }
  92.  
  93. int encryptndecrypt::encrypt_now(string szKey)
  94. {
  95.     string::iterator it;
  96.  
  97.     for(it=szKey.begin();it<szKey.end();it++)
  98.     {
  99.         if(*it=='1')
  100.             szEncryptedKey.push_back('0');
  101.         if(*it=='2')
  102.             szEncryptedKey.push_back('(');
  103.         if(*it=='3')
  104.             szEncryptedKey.push_back('8');
  105.         if(*it=='4')
  106.             szEncryptedKey.push_back('&');
  107.         if(*it=='5')
  108.             szEncryptedKey.push_back('6');
  109.         if(*it=='6')
  110.             szEncryptedKey.push_back('%');
  111.         if(*it=='7')
  112.             szEncryptedKey.push_back('4');
  113.         if(*it=='8')
  114.             szEncryptedKey.push_back('#');
  115.         if(*it=='9')
  116.             szEncryptedKey.push_back('2');
  117.         if(*it=='0')
  118.             szEncryptedKey.push_back('!');
  119.         if(*it=='q')
  120.             szEncryptedKey.push_back('@');
  121.         if(*it=='w')
  122.             szEncryptedKey.push_back('$');
  123.         if(*it=='e')
  124.             szEncryptedKey.push_back('^');
  125.         if(*it=='r')
  126.             szEncryptedKey.push_back('*');
  127.         if(*it=='t')
  128.             szEncryptedKey.push_back(')');
  129.         if(*it=='y')
  130.             szEncryptedKey.push_back('-');
  131.         if(*it=='u')
  132.             szEncryptedKey.push_back('`');
  133.         if(*it=='i')
  134.             szEncryptedKey.push_back('=');
  135.         if(*it=='o')
  136.             szEncryptedKey.push_back('_');
  137.         if(*it=='p')
  138.             szEncryptedKey.push_back('+');
  139.         if(*it=='[')
  140.             szEncryptedKey.push_back('{');
  141.         if(*it=='{')
  142.             szEncryptedKey.push_back('[');
  143.         if(*it==']')
  144.             szEncryptedKey.push_back('}');
  145.         if(*it=='}')
  146.             szEncryptedKey.push_back(']');
  147.         if(*it=='\\')
  148.             szEncryptedKey.push_back('|');
  149.         if(*it=='|')
  150.             szEncryptedKey.push_back('\\');
  151.     }
  152.  
  153.     Menu();
  154.     for(int i=0;i<80;i++)
  155.         cout<<'*';
  156.  
  157.     cout<<"\n"<<"Encrypted Code: ";
  158.     cout<<'\n'<<setw(80)<<right<<szEncryptedKey<<flush<<endl;
  159.  
  160.     for(int i=0;i<80;i++)
  161.         cout<<'*';
  162.     Sleep(1300);
  163.  
  164.     return (szEncryptedKey!="" ? 1:0);
  165. }
  166.  
  167. void encryptndecrypt::save()
  168. {
  169.     myFile.open("info.bin",ios::binary|ios::app|ios::out);
  170.     MD5 md5;
  171.  
  172.     if(myFile.is_open())
  173.     {
  174.         szMD5Key=md5.digestString(const_cast<char*>(szEncryptedKey.c_str()));
  175.         myFile<<"\r\n#E~ "<<szMD5Key<<" ";
  176.         myFile.write(szEncryptedKey.c_str(),szEncryptedKey.length());
  177.     }
  178.     else
  179.     {
  180.         error=ERR_UNABLETOSAVE;
  181.         fnError(error);
  182.     }
  183.  
  184.     myFile.close();
  185. }
  186.  
  187. void encryptndecrypt::fnClearInstance()
  188. {
  189.     password.clear();
  190.     szEncryptedKey.clear();
  191.     szDecryptedKey.clear();
  192.     szMD5Key.clear();
  193. }
  194.  
  195. bool encryptndecrypt::fnSaveMD5ToClipboard()
  196. {
  197.     char* pszTemp=const_cast<char*>(szMD5Key.c_str());
  198.     const size_t len=strlen(pszTemp) + 1;
  199.     HGLOBAL hMem=GlobalAlloc(GMEM_MOVEABLE,len);
  200.  
  201.     memcpy(GlobalLock(hMem),pszTemp,len);
  202.     GlobalUnlock(hMem);
  203.     if(OpenClipboard(0))
  204.     {
  205.         EmptyClipboard();
  206.         SetClipboardData(CF_TEXT, hMem);
  207.         CloseClipboard();
  208.         return true;
  209.     }
  210.     GlobalFree(hMem);
  211.  
  212.     return false;
  213. }
  214.  
  215. #endif  //MAIN_H