import
binascii
print
(
'输入信息:'
)
username_Str
=
'KCTF'
builtin_HexStr
=
'C6E4CAB5CED2B8FCCFB2BBB6CBEFBCE1'
print
(
'username:\t%s'
%
(username_Str))
print
(
'builtinHex:\t%s'
%
(builtin_HexStr))
print
(
'\n转换成字节流'
)
username_Bytes
=
str
.encode(username_Str)
builtin_Bytes
=
binascii.unhexlify(builtin_HexStr)
print
(
'username:\t%s'
%
(username_Bytes))
print
(
'builtinHex:\t%s'
%
(builtin_Bytes))
print
(
'\n转换成整数:小端获取'
)
username_hex
=
int
.from_bytes(username_Bytes, byteorder
=
'little'
)
builtin_Hex
=
int
.from_bytes(builtin_Bytes, byteorder
=
'little'
)
print
(
'username:\t%02X'
%
(username_hex))
print
(
'builtinHex:\t%02X'
%
(builtin_Hex))
print
(
'\n异或操作:此结果是字节反转的。主要是为了进行异或操作的对齐'
)
xorAB
=
username_hex^builtin_Hex
print
(
'xor:\t\t%02X'
%
(xorAB))
print
(
'\n转换成字节流'
)
SN_Re_HexStr
=
'%02X'
%
(xorAB)
SN_Re_Bytes
=
binascii.unhexlify(SN_Re_HexStr)
print
(
'序列号字节流:\t%s'
%
(SN_Re_Bytes))
print
(
'\n转换成整数:小端获取'
)
SN
=
int
.from_bytes(SN_Re_Bytes, byteorder
=
'little'
)
print
(
'序列号:\t\t%02X'
%
(SN))