[PYTHON-CRYPTO] amkCrypto: Cipher decrypt(string) output
Jason R. Mastaler
jason-list-python-crypto at MASTALER.COM
Wed Mar 28 02:43:39 CEST 2001
"Jason R. Mastaler" <jason-list-python-crypto at MASTALER.COM> writes:
> I'm experimenting with amkCrypto, and I'm confused about the output
> I'm getting back from a decrypted string.
>
> #!/usr/bin/env python
> import time
> from Crypto.Cipher import Blowfish
> key = '146bfea4ab7274e6f0ccff25351c2f39'
> cipherobj=Blowfish.new(key, Blowfish.CBC)
> input = '%16d' % (time.time() +1)
> dated_cookie = cipherobj.encrypt(input)
> plaintext = cipherobj.decrypt(dated_cookie)
>
> print input
> print plaintext
>
> This code produces the following output where `*' is really a binary
> character:
>
> 985728133
> ********85728133
>
> Why aren't input and plaintext identical? The strings end the same,
> but plaintext has some binary characters at its beginning.
Strangely, if I create a new cipher object using ECB mode instead of
CBC mode, I no longer have this problem, but I'm unsure as to why this
makes a difference. Here is the above piece of code with only line 5
changed:
#!/usr/bin/env python
import time
from Crypto.Cipher import Blowfish
key = '146bfea4ab7274e6f0ccff25351c2f39'
cipherobj=Blowfish.new(key, Blowfish.ECB)
input = '%16d' % (time.time() +1)
dated_cookie = cipherobj.encrypt(input)
plaintext = cipherobj.decrypt(dated_cookie)
print input
print plaintext
Output:
985740024
985740024
More information about the python-crypto
mailing list