Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34580
| References | <d6779e35-32b8-417a-abf9-72454573bf56@googlegroups.com> |
|---|---|
| Date | 2012-12-11 00:25 +0100 |
| Subject | Re: String manipulation in python..NEED HELP!!!! |
| From | Vlastimil Brom <vlastimil.brom@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.692.1355181961.29569.python-list@python.org> (permalink) |
2012/12/10 <qbailey@ihets.org>:
> 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..."
>
>
>
>
> i really need help on how to encrypt it im not sure how to go about doing that please help.
> --
> http://mail.python.org/mailman/listinfo/python-list
Hi,
if I understand correctly, for the data shown in the code, you may
probably use the translate method of the string (and the corresponding
maketrans method);
cf.:
python 2.7
>>> import string
>>> "ABCDEF...VWXYZ".translate(string.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "XPMGTDHLYONZBWEARKJUFSCIQV"))
'XPMGTD...SCIQV'
>>>
python 3.2
>>> "ABCDEF...VWXYZ".translate("".maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "XPMGTDHLYONZBWEARKJUFSCIQV"))
'XPMGTD...SCIQV'
>>>
hth,
vbr
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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