diff --git a/ceaser_cipher.py b/ceaser_cipher.py new file mode 100644 index 0000000..344fdd8 --- /dev/null +++ b/ceaser_cipher.py @@ -0,0 +1,29 @@ + +def ceaser_cipher(text: str, s: int) -> str: + """ Returns the input text in encrypted form + + >>> ceaser_cipher(Hello!@2world, 3) + Returns -> Khoor!@2zruog + + """ + result = "" + + for i in range(len(text)): # Traverse the text + char = text[i] + + # Encrypt According to the case + if (char.isupper()): + result += chr((ord(char) + s-65) % 26 + 65) + + elif (char.islower()): + result += chr((ord(char) + s - 97) % 26 + 97) + + else: # Do not encrypt non alpha characters + result += char + + return result + +if __name__ == "__main__": + txt = input("Enter text to Encrypt: ") + key = int(input("Enter Your Key: ")) + print("Encrypted Text:", ceaser_cipher(txt, key))