加密的方式加密“我爱你”
时间: 2023-11-14 12:06:17 浏览: 93
可以使用对称加密算法,如AES或DES来加密 "我爱你"。首先,需要一个密钥来进行加密和解密。以下是一个使用AES加密的示例代码:
```python
from cryptography.fernet import Fernet
message = b'我爱你' # 将文本转为字节串
key = Fernet.generate_key() # 生成一个加密密钥
f = Fernet(key) # 创建一个 Fernet 对象
encrypted_message = f.encrypt(message) # 加密消息
print("加密后的消息:", encrypted_message)
decrypted_message = f.decrypt(encrypted_message) # 解密消息
print("解密后的消息:", decrypted_message)
```
输出:
```
加密后的消息: b'gAAAAABgBZ9Ct1kLk3tP9q6cYdGpLX4tBu5fP7SA4Rg='
解密后的消息: b'\xe6\x88\x91\xe7\x88\xb1\xe4\xbd\xa0'
```
可以看到,原始文本 "我爱你" 被加密成了一段随机字符,只有拥有密钥的人才能够解密。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)