We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,534 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

String manipulation

I need help with a program i am doing. it is a cryptography program. i am given a regular alphabet and a key. i need to use the user input and use the regular alphabet and use the corresponding letter in the key and that becomes the new letter. i have the basic code but need help with how to mainpulate the string to do the encryption/decryption. please help

here is my code so far:

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

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key =   "XPMGTDHLYONZBWEARKJUFSCIQV"

def main():
  keepGoing = True
  while keepGoing:
    response = menu()
    if response == "1":
      plain = raw_input("text to be encoded: ")
      print encode(plain)
    elif response == "2":
      coded = raw_input("code to be decyphered: ")
      print decode(coded)
    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..."
2
Contributors
1
Reply
6 Hours
Discussion Span
6 Months Ago
Last Updated
3
Views
tizzqman
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Try this for a hint

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key = "XPMGTDHLYONZBWEARKJUFSCIQV"
for ctr in range(len(alpha)):
    print alpha[ctr], key[ctr]

print
print alpha.find("F")
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 780
Skill Endorsements: 9

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0563 seconds using 2.65MB