python - 使用变量 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 - 如何按数组元素的第一项排序?
- sap-cloud-platform - 如何使用蓝绿模式在 SAP Cloud Foundry 中进行部分重新部署?
- gremlin - Gremlin:具有静态和动态的属性名称
- svg - 是否可以将以 objectBoundingBox 坐标表示的径向渐变转换为 userSpaceOnUse 坐标?
- pnpm - pnpm list -g 显示一些包为“未保存”,这是什么意思?
- javascript - 如何在咖啡文件的 rails 表达式中获取 js/coffee 变量?
- python - Python Discord.py TextChannel 创建覆盖错误
- r - 如何计算满足条件的多个 .csv 文件中的行数,以便将它们绘制在 R 中的条形图上?
- node.js - 如何将连续运行的代码添加到nodejs postgresql客户端中?
- flutter - IntelliJ Idea 中的 Dart / Flutter sdk 位置,有没有办法为特定项目设置它们?