Рубрики
Без рубрики

Цезарь шифр

# упражнение7.py # Эта программа может кодировать и декодировать Цезарь шифры. # от: Скотт Гордон Деф Майн (): … Tagged с помощью Python, программирования, информатики.

# exercise7.py
# This program can encode and decode Caesar ciphers.
# by: Scott Gordon

def main():
    # Create a welcome message.
    print("***** Welcome to the Ceasar Cipher Encoder / Decoder ******")

    encode_decode_choice = int(
        input("Enter 1 to encode or enter 2 to decode: "))
    result = ""

    if encode_decode_choice == 1:
        # Input a string of plaintext to encode, and the value of a key.
        text = input("Enter the text you would like to encode here: ")
        key = int(input("Enter the Caesar cipher key here: "))
        # TODO Shift the letters of the string pus the number of the key.
        for ch in text:
            result += chr((ord(ch))+key)

    elif encode_decode_choice == 2:
        # Input a string of plaintext to decode, and the value of a key.
        text = input("Enter the text you would like to decode here: ")
        key = int(input("Enter the Caesar cipher key here: "))
        # Shift the letters of the string minus the number of the key.
        for ch in text:
            result += chr((ord(ch))-key)

    # Output the encoded / decoded message 
    print(result)


main()

Фотография Илона Фрей на Неспособный

Оригинал: “https://dev.to/sagordondev/caesar-cipher-30e3”