Cryptography - Encrypt and Decrypt data in Python

Updated: Jan 16

What is Cryptography?

Cryptography is the science of protecting information and used to provide secrecy to our data from third parties. Basically cryptography is a encrypted message in which letters are replaced with other characters.

What are Encryption and Decryption?

Encryption is the process of converting normal plain text into unintelligible (meaningless) text. Decryption is the process of transforming encrypted information into its normal form or original form.

Python Code:

import os
def clear_screen():
    os.system('cls' if == 'nt' else 'clear')
n = True
while n:
    message = input("Enter your message: ")
    key = int(input("Enter any key between (1-9):"))
    print("\n What do you want to do from this Message")
    c = int(input("1 For Encryption\n2 For Decryption\n3 Exit\n\nEnter your Choice: "))

    if c == 1:
        s = ""
        p = 0
        print("Encrypted Message is :- ")
        for i in message:
            s = s + chr(ord(i)+key-p)
            p += 1
        message = s
        print("\t", message)
    elif c == 2:
        s = ""
        p = 0
        print("Decrypted Message is :- ")
        for i in message:
            s = s + chr(ord(i)-key+p)
            p += 1
        message = s
        print("\t", message)
    elif c == 3:
        print("See you again")
        n = False
        print("Have a look on the choice options")
    input("\n Press ENTER to continue")

Code and Output:

72 views0 comments

Recent Posts

See All


26, Buddhadeb Bose Road, Ashrampara, Siliguri

©2020 by Filamenting. Proudly created with