Simple Encryption

David Brown david at no.westcontrol.spam.com
Tue Nov 19 05:21:22 EST 2002


"Bronek Carr" <BCARR1 at uk.ibm.com> wrote in message
news:ard013$obo$1 at sp15at20.hursley.ibm.com...
> Hi all,
>
> I am trying to write a simple ROT-13 encryption script in python.  A good
> starting point would be a function which gets the ascii value of a
character
> in a string.  I would assume this function already exists in one of the
> packages, as it does in every other language I use.  I cannot find it if
it
> does, can anyone help me.
>
>
> Thanks in advance
>
> Bronek
>
>

You are looking for the "ord" function:

>>> ord('a')
97
>>> map(ord, "Hello, world!")
[72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]
>>>

The inverse is "chr" :

>>> chr(97)
'a'
>>> map(chr, [72, 101, 108, 108, 111])
['H', 'e', 'l', 'l', 'o']
>>> "".join(map(chr, [72, 101, 108, 108, 111]))
'Hello'
>>>







More information about the Python-list mailing list