Welcome Guest [Log In] [Register]
Viewing Single Post From: Urrrgh! Help Plz
jdege
Member Avatar
Elite member
[ *  *  *  *  * ]
loki
Mar 7 2007, 01:36 AM
I am not grasping how to implement CBC whatsoever, I have tried and tried and just can't figure out where i am going wrong.

There's nothing wrong with your C.

Well, there's a lot wrong with your C - K&R bracing, screwy indents, use of obsolete modifiers like "register" and "inline", but none of that has anything to do with why your code isn't working.

Your problem is your use of the "last" variable in decrypt.

Remember your formulas:
Code:
 

C[0] = E(P[0]^IV)             P[0] = D(C[0])^IV
C[n] = E(P[n]^C[n-1])      P[n] = D(C[n])^C[n-1]


When you're encrypting, you have "last" storing the last output character, C[n-1].

When you're decrypting, you have "last" storing the last output character, P[n-1].

But in decrypt, you're supposed to XOR the previous ciphertext character, not the previous plaintext character.

In decrypt, "last" should be set to the "current_byte", after you've decrypted "current_byte" and before you do the next fgetc().
When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.
Offline Profile Quote Post
Urrrgh! Help Plz · Off-topic