我读过某个地方,其他人也读过您的邮件。 使用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