[Tutor] encryption
Daniel Coughlin
kauphlyn@speakeasy.org
Tue, 22 May 2001 15:12:02 -0700 (PDT)
First off i think using a dictionary would help you enormously:
dict = {'a':'1','b':'2' ... }
then your function could look something like this:
def letters(ltter):
dict = {'a':'1','b':'2' ... }
print dict[ltter]
then you could do your translation like this:
>c = 'aaabbb'
>for letter in c:
> letters(letter)
1
1
1
2
2
2
or put the values where ever you need to. I think using a dictionary would be a
lot faster than using if statements.
On Tue, 22 May 2001, Katharine Stoner wrote:
> Hi to all python people,
>
> 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.
> -thanks
> Cameron
>
> Here is what I have so far:
>
> def letters(ltter):
> if ltter == ' ':
> print '~'
> if ltter == '':
> print '`'
> if ltter == 'A':
> print '1'
> if ltter == 'B':
> print '2'
> if ltter == 'C':
> print '3'
> if ltter == 'D':
> print '4'
> if ltter == 'E':
> print '5'
> if ltter == 'F':
> print '6'
> if ltter == 'G':
> print '7'
> if ltter == 'H':
> print '8'
> if ltter == 'I':
> print '9'
> if ltter == 'J':
> print '10'
> if ltter == 'K':
> print '11'
> if ltter == 'L':
> print '12'
> if ltter == 'M':
> print '13'
> if ltter == 'N':
> print '14'
> if ltter == 'O':
> print '15'
> if ltter == 'P':
> print '16'
> if ltter == 'Q':
> print '17'
> if ltter == 'R':
> print '18'
> if ltter == 'S':
> print '19'
> if ltter == 'T':
> print '20'
> if ltter == 'U':
> print '21'
> if ltter == 'V':
> print '22'
> if ltter == 'W':
> print '23'
> if ltter == 'X':
> print '24'
> if ltter == 'Y':
> print '25'
> if ltter == 'Z':
> print '26'
>
>
>