python decode(' hex')返回空ASCII字符串

时间:2015-02-08 02:17:28

标签: string python-2.7

我尝试使用加密库加密所有零。但是,在我进行解码后,该值消失了。如何在解码十六进制后获取ASCII值?

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))

输出

ctr = 00000000000000000000000000000000
ctr_a = 

1 个答案:

答案 0 :(得分:1)

它不是空的,只是00是一个空字符,它在终端中什么都不显示

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

返回

00000000000000000000000000000000
16

如果您将其中一个集合更改为将渲染到屏幕的角色,您将看到差异

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

输出

00650000000000000000000000000000
16
"e"