[英]How to put a set of Hexadecimal number as a String?
I want to compute the key
of round 10 based another key
, It works very well if ikk
is a string, so how to convert it into a string? 我想计算
key
的基础又一轮的10 key
,它工作得很好,如果ikk
是一个字符串,所以如何将它转换成字符串?
def test():
##### ikk= '000102030405060708090a0b0c0d0e0f' ===> It works!!!
ikk= 000102030405060708090a0b0c0d0e0f
ik=str(ikk)
data = [re.findall('..', item) for item in key.split('\n')]
for item in data:
if item:
result = [int(x, 16) for x in item]
print(result)
result = keyScheduleRounds(result, 0, 10)
tt=''.join(["%02x"%d for d in result])
print(tt)
Error that I found: 我发现的错误:
ik= str(000102030405060708090a0b0c0d0e0f) ^
SyntaxError: invalid token
If ikk is an hexadecimal number (and it looks like), try this way : ikk = 0x000102030405060708090a0b0c0d0e0f
. 如果ikk是十六进制数字(看起来像这样),请尝试以下方式:
ikk = 0x000102030405060708090a0b0c0d0e0f
。 Notice the 0x
at the beginning that will tell python this is an hexadecimal number, and not a decimal number. 请注意
0x
会告诉python这是一个十六进制数字,而不是十进制数字。
set ik : 设置ik:
ik= bytearray.fromhex("000102030405060708090a0b0c0d0e0f").decode()
This will convert hexadecimal to string. 这会将十六进制转换为字符串。 Full code is written below.
完整代码如下。
def test():
ik = bytearray.fromhex("000102030405060708090a0b0c0d0e0f").decode()
data = [re.findall('..', item) for item in key.split('\n')]
for item in data:
if item:
result = [int(x, 16) for x in item]
print(result)
result = keyScheduleRounds(result, 0, 10)
tt=''.join(["%02x"%d for d in result])
print(tt)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.