drdot
drdot

Reputation: 3347

python decode('hex') return empty ASCII string

I try to encrypt all zeros using the crypto library. However, after I do the decode, the value is gone. How can I get the ASCII value after the decode hex?

from Crypto.Cipher import AES
#..
#.. cipher initialization
#..

ctr_a = ctr.decode("hex") #hex coded string to hex string
print ctr
print ctr_a
temp = obj.encrypt(str(ctr_a))

output

ctr = 00000000000000000000000000000000
ctr_a = 

Upvotes: 0

Views: 1226

Answers (1)

David Parlevliet
David Parlevliet

Reputation: 502

It's not empty, it's just that 00 is a null character which displays nothing in a terminal

ctr = "00000000000000000000000000000000"
ctr_a = ctr.decode("hex") #hex coded string to hex string
print ctr
print len(ctr_a)

returns

00000000000000000000000000000000
16

If you change one of the sets to a character that will render to the screen you will see the difference

ctr = "00650000000000000000000000000000"
ctr_a = ctr.decode("hex") #hex coded string to hex string
print ctr
print len(ctr_a)
print '"%s"' % ctr_a

outputs

00650000000000000000000000000000
16
"e"

Upvotes: 1

Related Questions