Hello. I believe many of us have heard this cryptographic term before. I'll leave a few resources explaining how this encryption method works for those who are curious.
Source 1.
Source 2.
Source 3.
Source 4.
Now, let's move on to the console application we've created with Python. Here are a few visuals
===============================================
===============================================
Code
Kod:
__AUTHOR__ = "Helmsys"
############################### Sezar Şifreleme ###############################
class Colors: # Renk değişkenlerinin bulunduğu bir sınıf tanımlıyorum
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
class Caesar_encryption: # Gerekli şifreleme-çözme fonksiyonlarının bulunudğu bir sınıf tanımlıyorum
def __init__(self,text:str,key:int):
self.text = text
self.key = key
def encode(self): # Şifreleyen method
encode = ""
for i in self.text:
encode += chr(ord(i) + self.key) # "ord()" ASCII karakterin onluk karşılığını verir, "chr()" bu onluk değeri ASCII karakterine döndürür
return encode
def decode(self,decrypted): # Şifreli kelimeyi veya metni çözen method
decode = ""
for j in decrypted:
decode += chr(ord(j) - self.key)
return decode
def retry():
try:
query1 = input(f"{colors.BOLD}{colors.DARKCYAN}[{colors.RED}+{colors.DARKCYAN}]{colors.DARKCYAN} Encrypted-text {colors.RED}>>>{colors.CYAN} ") # Kullanıcı Girişi (normal-şifreli)
query2 = int(input(f"\t{colors.BOLD}{colors.PURPLE}\\____{colors.DARKCYAN}[{colors.RED}-{colors.DARKCYAN}]{colors.DARKCYAN} Key-value [int] {colors.RED}>>>{colors.CYAN} ")) # Kullanıcı girişi (tam sayı)
caesar = Caesar_encryption(text=query1,key=query2) # "caesar" adı ile "Caesar_encryption()" sınıfını örnekliyorum ardından parametrelere arguman olarak inputları veriyorum
if mainQuery == "1": # 1 seçili ise
print(f"\t{colors.BOLD}{colors.PURPLE}\\____{colors.DARKCYAN}[{colors.RED}!{colors.DARKCYAN}] Decrypted {colors.RED}{caesar.decode(query1)}{colors.END}")
elif mainQuery == "2": # 2 seçili ise
print(f"\t{colors.BOLD}{colors.PURPLE}\\____{colors.DARKCYAN}[{colors.RED}!{colors.DARKCYAN}] Encrypted {colors.RED}{caesar.encode()}{colors.END}")
except ValueError:
retry()
if __name__ == "__main__":
colors = Colors()
title = f"""{colors.BLUE}
Coding by
___| ____| | _)
| _` | _ \ __| _` | __| __| __ \ __| __| | | __ \ __| | _ \ __ \
| ( | __/\__ \ ( | | | | | ( | | | | | | | ( | | |
\____|\__,_|\___|____/\__,_|_| _____|_| _|\___|_| \__, | .__/ \__|_|\___/ _| _|
____/ _|
{colors.DARKCYAN}Helmsys
{colors.BOLD}{colors.CYAN}[{colors.RED}1{colors.CYAN}] Decrypt [Çöz]\t\t\t {colors.BOLD}{colors.CYAN}[{colors.RED}2{colors.CYAN}] Encrypt [Şifrele]
"""
print(title)
mainQuery = input(f"{colors.BOLD}{colors.DARKCYAN}[{colors.RED}!{colors.DARKCYAN}]{colors.DARKCYAN} Process {colors.RED}>>>{colors.CYAN} ")
if mainQuery == "1" or mainQuery == "2":
retry()
else:
raise ValueError(f"{colors.END}{colors.RED}Tanımlanmayan bir değer!{colors.END}") # 1 veya 2 dışında girilen bir değer varsa hata döndürür.