Skip to content
Closed
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
69 changes: 69 additions & 0 deletions Projects/Message_Encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import random as ra

Check failure on line 1 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (INP001)

Projects/Message_Encryption.py:1:1: INP001 File `Projects/Message_Encryption.py` is part of an implicit namespace package. Add an `__init__.py`.

Check failure on line 1 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (INP001)

Projects/Message_Encryption.py:1:1: INP001 File `Projects/Message_Encryption.py` is part of an implicit namespace package. Add an `__init__.py`.
import string as str

Check failure on line 2 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (A004)

Projects/Message_Encryption.py:2:18: A004 Import `str` is shadowing a Python builtin

Check failure on line 2 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (A004)

Projects/Message_Encryption.py:2:18: A004 Import `str` is shadowing a Python builtin


def options():
while True:
print("========== Welcome To Message Encryption ==========")
print("\t'1' For Encryption")
print("\t'2' For Decode")
try:
opt = int(input("Enter: "))
if opt not in ("1", "2", 1, 2):
print("Choose Number Between '1','2'")
if opt == 1:
encrypt()
elif opt == 2:
decode()
except ValueError:
print("Enter Numbers Only")


def encrypt():
x = input("Enter Your Message :")

if len(x) <= 3:
encrypt_key = input("Enter Your Key '1','4','7' :")

with open("User_Key.txt", "a+") as f:
f.write(f"{encrypt_key},{x}\n")
print(f"Successfully Encrypted: {x[::-1]}")

encrypt_key = input("Enter Your Key '1','4','7' :")

with open("User_Key.txt", "a") as f:
f.write(f"{encrypt_key},{x}\n")
shift = x[1:] + x[0]
prefix = "".join(ra.choice(str.ascii_letters) for _ in range(3))
suffix = "".join(ra.choice(str.ascii_letters) for _ in range(3))
message = prefix + shift + suffix
message = message.strip()
print(f"Successfully Encrypted: {message}")
return encrypt_key


def decode():
with open("User_Key.txt", "r") as f:

Check failure on line 46 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (UP015)

Projects/Message_Encryption.py:46:31: UP015 Unnecessary mode argument help: Remove mode argument

Check failure on line 46 in Projects/Message_Encryption.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (UP015)

Projects/Message_Encryption.py:46:31: UP015 Unnecessary mode argument help: Remove mode argument
user_message = input("Enter Message To Decode : ")
decode_key = input("Enter Your Key : ")
found = False

for line in f:
encrypt_key, x = line.strip().split(",")

if encrypt_key == decode_key:
if len(user_message) <= 3:
print(user_message[::-1])
else:
x = user_message[3:-3]
x = x[-1] + x[:-1]
print(f"Message Decoded : {x}")

found = True
break

if not found:
print("Didn't Match :/")


options()
Loading