diff --git a/Caesar_Cipher/Caesar_cipher.py b/Caesar_Cipher/Caesar_cipher.py index ac514ef3..64eea111 100644 --- a/Caesar_Cipher/Caesar_cipher.py +++ b/Caesar_Cipher/Caesar_cipher.py @@ -1,45 +1,43 @@ -class main: - def __init__(self,key:dict) -> None: +class Cipher: + def __init__(self, key: dict) -> None: self.key = key - - def get_input(self) -> None: + self.rev_key = {v: k for k, v in key.items()} # reverse mapping + + def get_input(self) -> None: while True: - blank_string = str(input("Enter string to decrypt: ")) - if blank_string.isalpha(): - blank_string = blank_string.lower() - self.blank_string = blank_string + text = input("Enter string to encrypt: ").strip() + if text.isalpha(): + self.blank_string = text.lower() break else: - print("Input is not valid") - continue - + print("Input is not valid! Only alphabets allowed.") + def encrypt_string(self) -> str: output = "" for c in self.blank_string: - for k,v in self.key.items(): - if k == c: - output += v - else: - continue - self.decrypted_string = output - return(output) - + output += self.key.get(c, c) + return output + def decrypt_string(self, string: str) -> str: - output = "" - string = string.lower() - string = string.strip() + string = string.strip().lower() if string == "": - return(self.blank_string) - else: - for c in string: - for k,v in self.key.items(): - if v == c: - output += k - - return(output) + return self.blank_string + output = "" + for c in string: + output += self.rev_key.get(c, c) + return output if __name__ == "__main__": - key ={"a": "d", "b": "e", "c": "f", "d": "g", "e": "h", "f": "i", "g": "j", "h": "k", "i": "l", "j": "m", "k": "n", "l": "o", "m": "p", "n": "q", "o": "r", "p": "s", "q": "t", "r": "u", "s": "v", "t": "w", "u": "x", "v": "y", "w": "z", "x": "a", "y": "b", "z": "c"} - main = main(key=key) - main.get_input() - print(main.encrypt_string()) + # Fixed: Caesar cipher with shift of 3 (properly wrapping around) + key = { + "a": "d", "b": "e", "c": "f", "d": "g", "e": "h", "f": "i", "g": "j", + "h": "k", "i": "l", "j": "m", "k": "n", "l": "o", "m": "p", "n": "q", + "o": "r", "p": "s", "q": "t", "r": "u", "s": "v", "t": "w", "u": "x", + "v": "y", "w": "z", "x": "a", "y": "b", "z": "c" + } + + cipher = Cipher(key) + cipher.get_input() + encrypted = cipher.encrypt_string() + print("Encrypted:", encrypted) + print("Decrypted:", cipher.decrypt_string(encrypted)) \ No newline at end of file diff --git a/Caesar_Cipher/README.md b/Caesar_Cipher/README.md index e6e8e0f5..78de4084 100644 --- a/Caesar_Cipher/README.md +++ b/Caesar_Cipher/README.md @@ -26,8 +26,12 @@ The script was created with Python3 and the built-in functions in it ```bash python3 caesarcypher.py -Enter string to decrypt: hello +Enter string to encrypt: hello khoor + +Enter string to decrypt: khoor +hello + ``` ## 📺 Demo

diff --git a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 b/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 deleted file mode 100644 index f5611fcf..00000000 Binary files a/NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3 and /dev/null differ