473,396 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

Encrypting your mails using Python

kudos
127 Expert 100+
I read somewhere that other people read your mail. People that are using gmail reports that that they seems to get ads related to their mails, so perhaps Google reads it! After reading this, panic and paranoia strikes, and you wonder, what could I do about this?

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
  1. import smtplib,math
  2. from Crypto.Cipher import DES
  3.  
  4. message = """
  5. this is a secret message send from bytes.com
  6. -kudos
  7. """
  8.  
  9. # need to be divisible by 8 so we add extra ' '
  10.  
  11. v = len(message) / 8.0
  12. w = int(math.ceil(v) * 8.0)
  13. for i in range(w-len(message)):
  14.  message = message+" "
  15.  
  16. # here we add a key to encrypt the message, which we choose to be "thebytes"
  17.  
  18. des = DES.new('thebytes', DES.MODE_ECB)
  19. crypted = des.encrypt(message)
  20.  
  21. # create a string which will be easier to decode from mail
  22.  
  23. s=""
  24. for x in crypted:
  25.  s+=str(ord(x))+"#"
  26. s = s[0:len(s)-1] # remove the last '#'
  27.  
  28. # try to decode it, normally you would insert content from a mail
  29.  
  30. s2=""
  31. for b in s.split("#"):
  32.  s2+=chr(int(b))
  33.  
  34. print des.decrypt(s2) 
  35.  
  36. # now, mail it with gmail
  37.  
  38. server = smtplib.SMTP('smtp.gmail.com:587')  
  39. server.starttls()  
  40. server.login("your gmail username","your gmail password")
  41. server.sendmail("to address", "fron address", s)  
  42. server.quit()
  43.  
After coding this, you can't help thinking, "why would somebody read my emails in the first place? What do I have to hide?"
Jun 7 '13 #1
1 3332
dwblas
626 Expert 512MB
After coding this, you can't help thinking, "why would somebody read my emails in the first place? What do I have to hide?"
Why would someone want to gossip about my boring life, but it happens. This is a nice, simple/easy to understand example of Crypto.
Jun 24 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: neeson | last post by:
Alright, I'm fairly new to Python, and this one has got me stumped. I've just started to write a cli program that'll use readline, and I've attached the relevant bits. Here's the mystery: If I...
3
by: .DLL hell II - The Evil Empire Strikes Back | last post by:
I can't figure out how this side-by-side assembly stuff it supposed to work. I have a stack of four assemblies A has no references B references A & C C References A & B D References A, B and C...
11
by: Zone62 | last post by:
*could be old news *fenton and linson got married in san francisco last week *toews was best person *is true? *see any new posts with fenton-linson sig?
14
by: _iycrd | last post by:
After several frustrating attempts to wrap a native DLL w a C++/CLI DLL, I finally got an assembly to compile, only to find a *runtime* error. The app comes up fine. Test dialog displays. ...
3
by: comp.lang.php | last post by:
I have a counter that evokes the "Three Strikes You're Out" rule.. if you make more than N mistakes it auto-resets to avoid flooding $_SESSION with attempt after attempt, etc. However, the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.