首页 > 解决方案 > 使用变量 binascii.hexlify(variable)

问题描述

我如何为 binascii.hexlify 使用变量?像这样:

test = "\x17\xebaAj\xe7\xddr5\x1c\xcec\x00\xff\xbc\xd1\xf7UP\x86cYnv\xcb\xbd\xeb.\nk\x1a\xd6"
two = binascii.hexlify(test)

我正在搜索并找到这个,但解码/编码没有给我正确的结果:

https://stackoverflow.com/questions/48677060/binascii-hexlifybvariable-is-this-possible

使用 b 它工作完美

one = binascii.hexlify(b'\x17\xebaAj\xe7\xddr5\x1c\xcec\x00\xff\xbc\xd1\xf7UP\x86cYnv\xcb\xbd\xeb.\nk\x1a\xd6')
print(one)

编辑:此代码生成的此 ASCII Bin:

import hashlib
import binascii

email = "admin@admin"
password = "admin"
# To uppercase
username = email.upper()
password = password.upper()
# username to hash
username = hashlib.sha256(username.encode('utf-8'))
username = username.hexdigest()
# combine username(hash) with password and convert to uppercase
username_password = str((username + ":" + password).upper())
# hash username and password and convert to uppercase
username_password = hashlib.sha256(username_password.encode('utf-8'))
username_password = str(username_password.hexdigest()).upper()
# convert hex to bin
username_password = binascii.unhexlify(username_password)
# rev string and delete character
username_password = str(username_password[::-1])
username_password = str(username_password[:-1][1:][1:])

标签: python

解决方案


推荐阅读