Untitled
unknown
python
a year ago
555 B
7
Indexable
def encrypt(text, key): res = "" for char in text: if char.isalpha(): shift = key % 26 if char.islower(): new_char = chr((ord(char) - ord('a') + shift) % 26 + ord('a')) else: new_char = chr((ord(char) - ord('A') + shift) % 26 + ord('A')) res += new_char else: res += char return res text = input("Enter text to encrypt: ") key = int(input("Enter key: ")) encrypted_text = encrypt(text, key) print(encrypted_text)
Editor is loading...
Leave a Comment