What could we do in Python? First I want to add a message, then I want to encrypt it, send it with gmail, and then I would like to be able to decrypt it afterwards.
Expand|Select|Wrap|Line Numbers
- 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()