ctext = "09e1c5f70a65ac519458e7e53f36"
text= "hello"
text2= "goodbye"
htext = asctohex(text)
print text,"=",htext,"=",binascii.unhexlify(htext)
print "and using encode()",text.encode('hex')
print
text2= asctohex(text2)
print text2,"=",text2,"=",binascii.unhexlify(text2)
otp = operator.xor(int(htext,16), int(ctext,16))
cDusk = operator.xor(int(text2,16), otp)
我收到以下错误。但是我认为asctohex是来自库的Python的内置函数吗?
Traceback (most recent call last):
File "dawnq.py", line 11, in <module>
htext = asctohex(text)
NameError: name 'asctohex' is not defined
答案 0 :(得分:1)
asctohex
不是标准的Python函数。
您可能想要使用binascii.hexlify
。 (此函数与您已使用的unhexlify
相反。)
text = "hello"
hexVal = binascii.hexlify(text)
print text, " in hex is: ", hexVal