[Tutor] encryption

Lance E Sloan lsloan@umich.edu
Wed, 23 May 2001 09:11:57 -0400


"Katharine Stoner" wrote:
> I am working on a very simple encryption program.  The program replaces =
> all of the keys on the keyboard to numbers.  The problem is that I =
> cannot get letters to be traded for the numbers very easily.  I can't =
> get it to be put in a function so when I make the GUI for encryption and =
> decription.  I also need to be able to transform a message into the =
> numbers through a loop in the translation function.  It gives me an =
> error when I try and use the function to change letters to numbers.  It =
> says name is not defined.  If someone would tell me what is wrong with =
> this function.  I need a new aproach.

Cameron/Katharine,

As others have suggested, using a dictionary, list, or simply using
ord() on each character would be the best thing to do.  I have a
comment on your algorithm, though.  If your original text is, "AZ",
your encrypted output should either have one number per line or
delimited by some other character, like spaces:

    1
    26

Or:

    1 26

Because if you run them all together, like this:

    126

It might be decrypted later as "ABF", for characters number one, two,
and six, rather than what you intended, "AZ", characters one and twenty
six.

Good luck!

--
Lance E Sloan
Web Services, Univ. of Michigan: Full-service Web and database design,
development, and hosting.  Specializing in Perl & Python CGIs.
http://websvcs.itd.umich.edu/ - "Putting U on the Web"