使用Python加密您的邮件
我在什么地方读到其他人看过你的邮件。使用Gmail的人报告说,他们似乎收到了与他们的邮件相关的广告,所以可能是谷歌阅读了它!读完这篇文章后,恐慌和偏执突然袭来,你会想,我能做些什么呢?
我们可以用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()
编码之后,你不禁会想,"为什么一开始就会有人读我的电子邮件?我有什么可隐瞒的?"
评论已关闭