Pan*_*tos 51 python string encryption binary
我是python编程的新手,我有点困惑.我尝试从字符串中获取字节以进行哈希和加密,但我得到了
b'...'
Run Code Online (Sandbox Code Playgroud)
b字符串前面的字符就像下面的例子一样.有没有办法避免这种情况?.任何人都可以提供解决方案吗?对不起这个愚蠢的问题
import hashlib
text = "my secret data"
pw_bytes = text.encode('utf-8')
print('print',pw_bytes)
m = hashlib.md5()
m.update(pw_bytes)
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
print b'my secret data'
Run Code Online (Sandbox Code Playgroud)
kro*_*ock 121
这应该做的伎俩:
pw_bytes.decode("utf-8")
Run Code Online (Sandbox Code Playgroud)
Pyt*_*sta 20
解码是多余的
你首先只有这个"错误",因为误解了正在发生的事情.
你得到的是b因为你编码到utf-8现在它是一个字节对象.
>> type("text".encode("utf-8"))
>> <class 'bytes'>
Run Code Online (Sandbox Code Playgroud)
修正:
Muh*_*nus 13
你去吧
f = open('test.txt','rb+')
ch=f.read(1)
ch=str(ch,'utf-8')
print(ch)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
91598 次 |
| 最近记录: |