Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Text_encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#encryption programming

import random
import string

chars = " " + string.punctuation + string.digits + string.ascii_letters
chars=list(chars)
key = chars.copy()

random.shuffle(key)

#print(chars)
#print(key)

#ENCRYPT

plain_text = input("Enter a message to encrypt: ")
cipher_text = ""

for letter in plain_text:
index = chars.index(letter)
cipher_text += key[index]

print(f"original message : {plain_text}")
print(f"encrypted message : {cipher_text}")

#decrypt
cipher_text = input("Enter a message to decrypt: ")
plain_text = ""

for letter in cipher_text:
index = key.index(letter)
plain_text += chars[index]

print(f"encrypted message : {cipher_text}")
print(f"original message : {plain_text}")