Tuesday, October 26, 2010

Simple encryption in Python

In this post I will demonstrate a simple program to encrypt any string in Python. The encryption is based on conversion to ASCII codes, and thus is very basic. What this program does is convert each letter of a string to its ASCII code (using ord() ), increase the ASCII code by 200, convert it back to characters and concatenate all the characters. The concatenated string is thus the encrypted text.

Here is the program-

string=input('Enter a string:')
text_enc_char=''
enc_factor=200
text_dec=''

for char in string:
        enc_char=ord(char)+enc_factor
        text_enc_char+=chr(enc_char)
print(text_enc_char)
I will write about decryption in the next post; meanwhile you can write your own code to decrypt text. Go ahead, decrypt this one- ĘŁēķĬĭĺ

For decrypting the text above go to the second part of this post here.