Python Forum
Homework: Ceaser Cipher encoder and decoder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework: Ceaser Cipher encoder and decoder
#9
Success!!! Thank you for the help. It was nice to see I wasn't too far from being correct. This is the most intricate program I've written so far. [edited] Ok, got a little ahead of myself. I tried the decrypter portion of the program and got a traceback error of
Error:
encrypted_message += chr(x + 65) NameError: name 'encrypted_message' is not defined
should I remove the method == str("decrypt") and change the elif back to an else?

message = input("Enter the message you wish to encrypt or decrypt:")
shift_key = int(input("Enter the key value:"))
method = str(input("Would you like to encrypt or decrypt a message?"))
if method != str("encrypt") and method != str("decrypt"):
    method = input("Enter either encrypt or decrypt")
else:
    if method == str("encrypt"):
        encrypted_message = ""
        for character in message:
            if character.isalpha() == True:
                if character == character.lower():
                    x = ord(character) -97
                    x += int(shift_key)
                    x = x % 26
                    encrypted_message += chr(x + 97)
                else:
                    x = ord(character) -65
                    x += int(shift_key)
                    x = x % 26
                    encrypted_message += chr(x + 65)
            else:
                encrypted_message += character
        print(encrypted_message)
    elif method == str("decrypt"):
        decrypted_message = ""
        for character in message:
            if character.isalpha() == True:
                if character == character.lower():
                    x = ord(character) -97
                    x += int(-shift_key)
                    x = x % 26
                    encrypted_message += chr(x + 97)
                else:
                    x = ord(character) -65
                    x += int(-shift_key)
                    x = x % 26
                    encrypted_message += chr(x + 65)
            else:
                decrypted_message += character
        print(decrypted_message)
Reply


Messages In This Thread
RE: Homework: Ceaser Cipher encoder and decoder - by Siylo - Oct-27-2018, 11:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Ceaser cipher program oli_action 5 2,986 Sep-14-2020, 10:43 AM
Last Post: oli_action
  Cipher Caesar Azilkhan 1 2,234 Nov-21-2019, 03:40 PM
Last Post: ichabod801
  Monoalphabetic cipher pawlo392 1 12,939 Apr-01-2019, 08:51 PM
Last Post: ichabod801
  Caesar cipher Drone4four 19 11,203 Nov-11-2018, 04:07 AM
Last Post: nilamo
  Playfair cipher encoder and decoder nuttinserious 1 6,016 Oct-23-2017, 06:41 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020