cbc mode not working
Created by: 7bug0110
Hi, the CBC mode is not working, you missed the part where you need to take the n block cipher as the IV for the block n+1 I mark the two lines to add with the // MISSING PART comments in the following function And thanks for the lib of course ! It saves me some time !
encryptCBC: function(string, iv) { string = this.utf8Decode(string); var blocks = Math.ceil(string.length/8); var ivL, ivR, ivLivR; ivLivR = this.split64by32(iv); ivL = ivLivR[0]; ivR = ivLivR[1]; var encryptedString = ""; for (var i = 0; i < blocks; i++) { var block = string.substr(i * 8, 8); if (block.length < 8) { var count = 8 - block.length; while (0 < count--) { block += "\0"; } } var xL, xR, xLxR; xLxR = this.split64by32(block); xL = xLxR[0]; xR = xLxR[1]; xL = this.xor(xL, ivL); xR = this.xor(xR, ivR); xLxR = this.encipher(xL, xR); xL = xLxR[0]; xR = xLxR[1]; encryptedString += this.num2block32(xL) + this.num2block32(xR); ivL = xL; // MISSING PART ivR = xR; // MISSING PART }