使用Python加密邮件

我读过某个地方,其他人也读过您的邮件。 使用gmail的人报告说他们似乎收到了与邮件相关的广告,因此Google可能会阅读! 读完这篇文章后,恐慌和偏执症发作了,您想知道,我该怎么办?

我们可以在Python中做什么? 首先,我想添加一条消息,然后将其加密,用gmail发送,然后再希望对其进行解密。


import smtplib,math
from Crypto.Cipher import DES 
message = """
this is a secret message send from bytes.com
-kudos
""" 
# need to be divisible by 8 so we add extra ' ' 
v = len(message) / 8.0
w = int(math.ceil(v) * 8.0)
for i in range(w-len(message)):
 message = message+" " 
# here we add a key to encrypt the message, which we choose to be "thebytes" 
des = DES.new('thebytes', DES.MODE_ECB)
crypted = des.encrypt(message) 
# create a string which will be easier to decode from mail 
s=""
for x in crypted:
 s+=str(ord(x))+"#"
s = s[0:len(s)-1] # remove the last '#' 
# try to decode it, normally you would insert content from a mail 
s2=""
for b in s.split("#"):
 s2+=chr(int(b)) 
print des.decrypt(s2)  
# now, mail it with gmail 
server = smtplib.SMTP('smtp.gmail.com:587')  
server.starttls()  
server.login("your gmail username","your gmail password")
server.sendmail("to address", "fron address", s)  
server.quit() 
编写此代码后,您不禁会想:“为什么首先要读我的电子邮件?我必须隐藏什么?”

翻译自: https://bytes.com/topic/python/insights/949869-encrypting-your-mails-using-python

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值