将大数字转换为chars-Python

将大数字转换为chars-Python,python,string,int,Python,String,Int,我有一门密码学课程,我要解密RSA芯片。现在,解密完成后,我希望将解密列表decryptList[]中的每个数字转换为字符,以便文本可读 在解密列表[0]中,我有13876633635707196740445712245626646062。我应该如何将这个数字转换为可读文本 我已尝试从字符串转换为int: plainText = "stackoverflow".encode('hex') plainInt = long(plainText,16) print plainInt => 914

我有一门密码学课程,我要解密RSA芯片。现在,解密完成后,我希望将解密列表decryptList[]中的每个数字转换为字符,以便文本可读

在解密列表[0]中,我有13876633635707196740445712245626646062。我应该如何将这个数字转换为可读文本

我已尝试从字符串转换为int:

plainText = "stackoverflow".encode('hex')
plainInt = long(plainText,16)
print plainInt
=> 9147256685580292608768854486903
现在我想从plainInt转到stackoverflow。
有什么建议我应该如何做到这一点

回答您的示例:使用十六进制从long向后返回到十六进制,并解码以从十六进制获取字符串:

>>> plain_hex = hex(plainInt)
>>> print plain_hex
0x737461636b6f766572666c6f77L
>>> str(plain_hex)[2:-1].decode('hex')
'stackoverflow'

在Python 2中,可以执行与将字符串转换为数字相反的操作:

>>> plainHex = hex(plainInt)[2:-1]
>>> plainHex.decode('hex')
'stackoverflow'
在Python 3中,int有一个to_bytes函数,该函数采用字节长度和字节顺序big或little endian:

>>> plainInt.to_bytes(13, byteorder='big')
b'stackoverflow'

这适用于Python2和Python3

import codecs
b = hex(plainInt).rstrip("L").lstrip("0x")
codecs.decode(b, 'hex').decode('utf-8')