Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef MAIN_H
- #define MAIN_H
- void fnError(int nErrCode)
- {
- cerr<<"\n\nError #"<<nErrCode<<" - Check help section for more information!";
- }
- enum ERROR_CODES
- {
- ERR_WRONGINPUT=101,ERR_ENCRYPTION=102,ERR_UNABLETOSAVE
- }error;
- char progress[27]={'/','\\','!','@','#','$','%','&','*','+','~','<','>',
- '/','\\','!','@','#','$','%','&','*','+','~','<','>','\0'};
- fstream myFile;
- void Menu()
- {
- system("CLS");
- cout<<"----------------------Welcome to Aceix Encryption Tool--------------------------";
- cout<<setw(80)<<right<<"v1.0"<<endl<<endl;
- }
- int fnMainMenu(int& iChoice)
- {
- cout<<"Select what you want to do by typing the number..."<<endl<<endl;
- cout<<"\t1. Encrypt a string."<<endl
- <<"\t2. Decrypt a string."<<endl
- <<"\t3. Goto: Help Section."<<endl
- <<"\t4. Exit this app."<<flush;
- cout<<"\n\n\tSelection: #";
- cin>>iChoice;
- if(cin.fail())
- {
- error=ERR_WRONGINPUT;
- fnError(error);
- cin.clear();
- iChoice=0;
- cin.ignore();
- }
- return iChoice;
- }
- class encryptndecrypt
- {
- protected:
- string password;
- string szEncryptedKey;
- string szDecryptedKey;
- string szMD5Key;
- public:
- encryptndecrypt()
- {
- string szEncryptedKey="";
- string szDecryptedKey="";
- }
- int encrypt();
- int decrypt();
- void save();
- void load();
- void fnClearInstance();
- bool fnSaveMD5ToClipboard();
- void showMD5()
- {
- cout<<szMD5Key;
- }
- private:
- int encrypt_now(string);
- int decrypt_now(string);
- };
- int encryptndecrypt::encrypt()
- {
- char random;
- srand(time(NULL));
- getline(cin,password);
- cout<<"\n\nPlease wait!\nEncrypting..."<<endl;
- for(unsigned i=0;i<password.length();i++)
- {
- random=progress[rand()%25];
- cout<<random;
- Sleep(500);
- }
- return (encrypt_now(password));
- }
- int encryptndecrypt::encrypt_now(string szKey)
- {
- string::iterator it;
- for(it=szKey.begin();it<szKey.end();it++)
- {
- if(*it=='1')
- szEncryptedKey.push_back('0');
- if(*it=='2')
- szEncryptedKey.push_back('(');
- if(*it=='3')
- szEncryptedKey.push_back('8');
- if(*it=='4')
- szEncryptedKey.push_back('&');
- if(*it=='5')
- szEncryptedKey.push_back('6');
- if(*it=='6')
- szEncryptedKey.push_back('%');
- if(*it=='7')
- szEncryptedKey.push_back('4');
- if(*it=='8')
- szEncryptedKey.push_back('#');
- if(*it=='9')
- szEncryptedKey.push_back('2');
- if(*it=='0')
- szEncryptedKey.push_back('!');
- if(*it=='q')
- szEncryptedKey.push_back('@');
- if(*it=='w')
- szEncryptedKey.push_back('$');
- if(*it=='e')
- szEncryptedKey.push_back('^');
- if(*it=='r')
- szEncryptedKey.push_back('*');
- if(*it=='t')
- szEncryptedKey.push_back(')');
- if(*it=='y')
- szEncryptedKey.push_back('-');
- if(*it=='u')
- szEncryptedKey.push_back('`');
- if(*it=='i')
- szEncryptedKey.push_back('=');
- if(*it=='o')
- szEncryptedKey.push_back('_');
- if(*it=='p')
- szEncryptedKey.push_back('+');
- if(*it=='[')
- szEncryptedKey.push_back('{');
- if(*it=='{')
- szEncryptedKey.push_back('[');
- if(*it==']')
- szEncryptedKey.push_back('}');
- if(*it=='}')
- szEncryptedKey.push_back(']');
- if(*it=='\\')
- szEncryptedKey.push_back('|');
- if(*it=='|')
- szEncryptedKey.push_back('\\');
- }
- Menu();
- for(int i=0;i<80;i++)
- cout<<'*';
- cout<<"\n"<<"Encrypted Code: ";
- cout<<'\n'<<setw(80)<<right<<szEncryptedKey<<flush<<endl;
- for(int i=0;i<80;i++)
- cout<<'*';
- Sleep(1300);
- return (szEncryptedKey!="" ? 1:0);
- }
- void encryptndecrypt::save()
- {
- myFile.open("info.bin",ios::binary|ios::app|ios::out);
- MD5 md5;
- if(myFile.is_open())
- {
- szMD5Key=md5.digestString(const_cast<char*>(szEncryptedKey.c_str()));
- myFile<<"\r\n#E~ "<<szMD5Key<<" ";
- myFile.write(szEncryptedKey.c_str(),szEncryptedKey.length());
- }
- else
- {
- error=ERR_UNABLETOSAVE;
- fnError(error);
- }
- myFile.close();
- }
- void encryptndecrypt::fnClearInstance()
- {
- password.clear();
- szEncryptedKey.clear();
- szDecryptedKey.clear();
- szMD5Key.clear();
- }
- bool encryptndecrypt::fnSaveMD5ToClipboard()
- {
- char* pszTemp=const_cast<char*>(szMD5Key.c_str());
- const size_t len=strlen(pszTemp) + 1;
- HGLOBAL hMem=GlobalAlloc(GMEM_MOVEABLE,len);
- memcpy(GlobalLock(hMem),pszTemp,len);
- GlobalUnlock(hMem);
- if(OpenClipboard(0))
- {
- EmptyClipboard();
- SetClipboardData(CF_TEXT, hMem);
- CloseClipboard();
- return true;
- }
- GlobalFree(hMem);
- return false;
- }
- #endif //MAIN_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement