I've having a lot of trouble implementing this. When my algorithm was in ECB mode it worked fine but i cant get the CBC to go. Anyone see what my error is?
the divyBlocks() function divides the plain-text into 128-bit blocks, the dDivyBlocks() function does the same but starts with the last block instead of the first.Code:void encryptDEA(string &ptext, string key, string &ctext) { //CBC Mode string prevBlock = ""; appendString(ptext); string block; int r = ptext.size()/16; //ENCRYPTION for(int i=r; i>0; i--) { divyBlocks(ptext, block, r); xor(block, prevBlock); encrypt(block, key); prevBlock = block; ctext += block; } } void decryptDEA(string ctext, string key, string &ptext) { //CBC Mode string block; int j; string prevBlock = ""; int r = ctext.size()/16; //DECRYPTION j = r; for(int i=0; i<j; i++) { dDivyBlocks(ctext, block, r); xor(block, prevBlock); decrypt(block, key); prevBlock = block; ptext += block; } }
Thanks!



LinkBack URL
About LinkBacks


