Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: String manipulation in python..NEED HELP!!!! Date: Mon, 10 Dec 2012 22:59:05 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 43 Message-ID: References: NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1355180345 16832 166.84.1.1 (10 Dec 2012 22:59:05 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 10 Dec 2012 22:59:05 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:34578 In qbailey@ihets.org writes: > """ 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..." > i really need help on how to encrypt it im not sure how to go about doing > that please help. def encode(plain): '''Return a substituted version of the plain text.''' encoded = '' for ch in plain: encoded += key[alpha.index(ch)] return encoded -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"