2
def m_encrypt(plaintext, key, final=""):
    for symbol in plaintext:
        final += chr((ord(symbol) + key - 13)%26 + ord('A'))
    return final.lower()

message = input("Enter the message: ")
message.lower()
e_key = int(input("Write the key: "))
print("Encrypted message:", m_encrypt(message, e_key))
1
  • Строка message.lower() не имеет смысла. 28 дек 2019 в 9:49

1 ответ 1

2
def m_encrypt(plaintext, key, final=""):
    plaintext = plaintext.lower()
    for symbol in plaintext:
        final += chr((ord(symbol) + key - ord('a'))%26 + ord('a'))
    return final.lower()

Так работает

Ошибка была в том, что порядок английской a - 97, а не 13 (A - 65)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.