Showing posts with label ascii. Show all posts
Showing posts with label ascii. Show all posts

Wednesday, November 3, 2010

Simple encryption (part2- Decryption)

In the last post, Simple encryption in Python, we discussed a simple way to use ASCII characters for encryption. If you haven't read that post I recommend that you do so before moving on.

In this post we will discuss how to decrypt the text we encrypted in the last post. The basic idea here is just to reverse the process we followed while encrypting.

text_enc_char=input('Enter encrypted text:')
enc_factor=200
for encchar in text_enc_char:
                dec_char=ord(encchar)+enc_factor
                text_dec+=chr(dec_char)

print(text_dec)

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.