DWKS:
Is this the right way to go about this CBC thing? Cause it wont work right =(
How do i implement the CBC correctly?Code://*****************ENCRYPT FILE FUNCTION*******************// void encryptFile(string filename) { //Get the contents of the file ifstream fin(filename.c_str()); char ch; string temp; while(fin.get(ch)) { temp += ch; } fin.close(); //Encrypt string encrypted; string hPassword; //Get the hash value of the password unsigned int hPass; ifstream fin2(SETUP_FILE); string getTemp; while(fin2.get(ch)) { getTemp += ch; } fin2.close(); int j; for(int i=0; i<getTemp.size(); i++) { if(getTemp.at(i) == '\n') j=(i+1); } for(j; j<getTemp.size(); j++) { hPassword += getTemp.at(j); } hPass = stringToInt(hPassword); //Encryption Algorithm Start encrypted.push_back(temp.at(0)^hPass); for(int i=1; i<temp.size(); i++) { encrypted.push_back(encrypted.at(i-1)^hPass); } //Encryption Algorithm End //Save to file ofstream fout(filename.c_str()); fout<<encrypted; fout.close(); } //**********************DECRYPT FILE FUNCTION************************// void decryptFile(string filename) { //Get the contents of the file ifstream fin(filename.c_str()); char ch; string temp; while(fin.get(ch)) { temp += ch; } fin.close(); //Encrypt string decrypted; string hPassword; //Get the hash value of the password unsigned int hPass; ifstream fin2(SETUP_FILE); string getTemp; while(fin2.get(ch)) { getTemp += ch; } fin2.close(); int j; for(int i=0; i<getTemp.size(); i++) { if(getTemp.at(i) == '\n') j=(i+1); } for(j; j<getTemp.size(); j++) { hPassword += getTemp.at(j); } hPass = stringToInt(hPassword); //Encryption Algorithm Start decrypted.push_back(temp.at(temp.size()-1)^hPass); for(int i=1; i < temp.size()-1; i++) { decrypted.push_back(decrypted.at(i-1)^hPass); } //Encryption Algorithm End //Save to file ofstream fout(filename.c_str()); fout<<decrypted; fout.close(); }