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
29 changes: 29 additions & 0 deletions ceaser_cipher.py
Original file line number Diff line number Diff line change
@@ -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))