fairplay
Fri Oct 20 2023 16:54:48 GMT+0000 (Coordinated Universal Time)
Saved by
@ahmed_salam21
def fairplay_cipher(text, key):
cipher = ""
key_length = len(key)
for i, char in enumerate(text):
if char.isalpha():
ascii_offset = 65 if char.isupper() else 97
key_char = key[i % key_length]
key_offset = ord(key_char) - ascii_offset
cipher += chr((ord(char) + key_offset) % 26 + ascii_offset)
else:
cipher += char
return cipher
# Example usage:
text = input("Enter the plaintext: ")
key = input("Enter the key: ")
result = fairplay_cipher(text, key)
print("Cipher:", result)
content_copyCOPY
Comments