【发布时间】:2019-06-21 17:58:37
【问题描述】:
我正在尝试在 Python 中实现 OS2IP 算法。但是我不知道如何转换字符串,说“少言寡语的人是最好的人”。成八进制格式。
【问题讨论】:
标签: python string encryption cryptography non-ascii-characters
我正在尝试在 Python 中实现 OS2IP 算法。但是我不知道如何转换字符串,说“少言寡语的人是最好的人”。成八进制格式。
【问题讨论】:
标签: python string encryption cryptography non-ascii-characters
使用str 的.encode() 方法。例如:
"öä and ü".encode("utf-8")
展示
b'\xc3\xb6\xc3\xa4 and \xc3\xbc'
如果您想将其转换为 int,您可以使用 int.from_bytes() 方法,例如
the_bytes = "öä and ü".encode("utf-8")
the_int = int.from_bytes(the_bytes, 'big')
print(the_int)
展示
236603614466389086088250300
在准备 RSA 加密时,通常对第一个编码步骤的结果应用填充算法,将字节数组填充到 RSA 模数的大小,然后将填充的字节数组转换为整数。此填充步骤对于 RSA 加密的安全性至关重要。
【讨论】: