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

Chris Angelico rosuav at
Tue Dec 11 00:36:12 CET 2012

On Tue, Dec 11, 2012 at 9:38 AM,  <qbailey at> wrote:
> 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

A few starting tips. Firstly, I'm going to assume here that this is a
homework question; you haven't said so, but it seems rather more
likely than the alternative (that you're actually going to use such an
incredibly low-grade cipher and an interactive prompt like this).
Please be honest about this; it's okay to ask for help, but we're not
here to do your homework for you. (We do NOT want to help you to get a
certificate you don't merit, then get a job using that certificate,
and then write code that we'll be staring at in our next jobs. There
are already more than enough incompetent programmers in the world; I'd
rather that you either learn the material for real, or if you can't,
fail the course honestly. Sorry if that sounds harsh, but I'm sure
you'd rather that I didn't have a certificate entitling me to drive a
truck on roads near you/your kids, because I do not know how to drive
one safely.)

Secondly, putting "NEED HELP" in your subject line doesn't, in fact,
help. :) It just makes you sound demanding.

So! On to the actual problem. What you need to do is find the letter
that corresponds to the one you have. Decryption is the same as
encryption but with the "alpha" and "key" switched, so I recommend
creating a function that accepts those two as arguments - something
like this:


def crypt(msg,from,to):
    # and put your code in here

# To encrypt:
encrypted = crypt(original, clear, key)

# To decrypt:
message = crypt(encrypted, key, clear)

The details of the encryption you can put together from John's and/or
vbr's responses, but make sure you understand the code yourself. For
example: What will each of them do with any non-alphabetic characters?
Suppose your original message is "HELLO, WORLD!" - what will happen to
the comma, space, and exclamation mark? Be sure you know *why* this is
how it is, too.

If you run into trouble, post your non-working code and exactly how
it's not working, and we'll try to help you understand why it's not
working. :) In the meantime, here's a document that you may want to
familiarize yourself with:

It's a great explanation of the how and, more importantly, the why of
asking questions of volunteer geeks.

All the best!


More information about the Python-list mailing list