Encrypt

Computer Science | Artificial Intelligence | Computational Biology | Chess | Blender

Encrypt

This is a simple python script that encrypts text using just the random library. The script takes a text file as input and encrypts the contents using a simple substitution cipher. The script then writes the encrypted text to the file.

Encryption Program

import string

# Char for recognizing the alphabet
char = string.ascii_letters + string.digits + string.punctuation + ' '
# Key used as a template for encryption
key = string.punctuation + string.digits + " " + string.ascii_letters
# Text to be encrypted
text = input('Enter the text to be encrypted: ')

# Encrypt the text function
def encrypt(text):
    encrypted_text = ''
    for i in text:
        encrypted_text += key[char.find(i)]
    return encrypted_text
# Call and print the encrypted text
print(encrypt(text))