[Tutor] encryption

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 22 May 2001 15:14:34 -0700 (PDT)


On Tue, 22 May 2001, 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.

Thankfully, there's a function called ord() that will do a lot of this
work for you: it will return the "ordinal" (number) of a character:

###
>>> ord('a')
97
>>> ord('b')
98
>>> ord('c')
99
>>> ord('A')
65
>>> ord('B')
66
>>> ord('C')
67
###

This itself will reallly help reduce the amount of work you'll be doing to
convert letters to numbers.


>  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. -thanks Cameron

Can you show us how you're using your letters() function?

Good luck to you!