Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cryptography help
#1
(encode/decode sections) Hello, I am having troubles actually taking the letter i found in the key or the alpha and making it the new plain for the main functions. Every time when I try to run the program it just says must be str not int. Which does make any sense because the string is a str. Any thoughts?

""" crypto.py
    Implements a simple substitution cypher
"""

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key =   "XPMGTDHLYONZBWEARKJUFSCIQV"


def menu():
    print('   Secret Decoder Menu')
    print()
    print('   0)' 'Quit')
    print('   1)' 'Encode')
    print('   2)' 'Decode')
    print()
    response = input('What would you like to do? ')
    return response

# when the user tpyes a number it sends the answer beck to the main function where it can be used in the while loop


def encode(plain):
    new_word = " "
    for letter in plain.upper():
        if letter in alpha:
            letter.find(key)
            keyLetter = letter.find(key)
            plain = new_word + keyLetter
    return plain


def decode(coded):
    new_word = " "
    for letter in coded.upper():
        if letter in key:
            letter.find(alpha)
            keyLetter = letter.find(alpha)
            coded = new_word + keyLetter
    return plain



def main():
  keepGoing = True
  while keepGoing:
    response = menu()
    if response == "1":
      plain = input("text to be encoded: ")
      print(encode(plain))
      print()
    elif response == "2":
      coded = input("code to be decyphered: ")
      print (decode(coded))
      print()
    elif response == "0":
      print ("Thanks for doing secret spy stuff with me.")
      keepGoing = False
    else:
      print ("I don't know what you want to do...")

main()
Reply


Messages In This Thread
cryptography help - by jorrdn - Mar-10-2018, 01:09 AM
RE: cryptography help - by Zman350x - Mar-10-2018, 02:18 AM
RE: cryptography help - by Larz60+ - Mar-10-2018, 03:41 AM
RE: cryptography help - by sparkz_alot - Mar-10-2018, 02:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [cryptography.io] How to convert DER signature to ECDSA fstefanov 1 3,062 Jul-04-2019, 08:59 AM
Last Post: fstefanov
  Cryptography in Python NLittle17 6 4,355 Jan-13-2019, 07:11 PM
Last Post: NLittle17
  Python cryptography or pycrypto lexlukkia 4 57,615 Jan-25-2017, 12:08 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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