Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34578

Re: String manipulation in python..NEED HELP!!!!

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 <gordon@panix.com>
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 <ka5pfp$ge0$1@reader1.panix.com> (permalink)
References <d6779e35-32b8-417a-abf9-72454573bf56@googlegroups.com>
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

Show key headers only | View raw


In <d6779e35-32b8-417a-abf9-72454573bf56@googlegroups.com> 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"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

String manipulation in python..NEED HELP!!!! qbailey@ihets.org - 2012-12-10 14:38 -0800
  Re: String manipulation in python..NEED HELP!!!! John Gordon <gordon@panix.com> - 2012-12-10 22:59 +0000
    Re: String manipulation in python..NEED HELP!!!! Terry Reedy <tjreedy@udel.edu> - 2012-12-11 14:30 -0500
      Re: String manipulation in python..NEED HELP!!!! Ross Ridge <rridge@csclub.uwaterloo.ca> - 2012-12-11 15:52 -0500
        Re: String manipulation in python..NEED HELP!!!! Tim Delaney <timothy.c.delaney@gmail.com> - 2012-12-12 08:34 +1100
  Re: String manipulation in python..NEED HELP!!!! Vlastimil Brom <vlastimil.brom@gmail.com> - 2012-12-11 00:25 +0100
  Re: String manipulation in python..NEED HELP!!!! Chris Angelico <rosuav@gmail.com> - 2012-12-11 10:36 +1100
  Re: String manipulation in python..NEED HELP!!!! duncan smith <buzzard@invalid.invalid> - 2012-12-11 16:39 +0000
    Re: String manipulation in python..NEED HELP!!!! Peter Pearson <ppearson@nowhere.invalid> - 2012-12-11 22:21 +0000

csiph-web