You are looking for the ord() function, I think:
>>> ord('a')
97
>>> ord('\u00c2')
192
This gives you the integer number for the Unicode codepoint.
To convert a whole set of characters use a list comprehension:
>>> [ord(c) for c in 'Hello World!']
[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]
It's inverse is the chr() function:
>>> chr(97)
'a'
>>> chr(193)
'Á'
Note that when you encrypt end decrypt text, you usually encode text to a binary representation with a character encoding. Unicode text can be encoded with different encodings with different advantages and disadvantages. These days the most commonly used encoding for Unicode text UTF-8, but others exist to.
In Python 3, binary data is represented in the bytes object, and you encode text to bytes with the str.encode() method and go back by using bytes.decode():
>>> 'Hello World!'.encode('utf8')
b'Hello World!'
>>> b'Hello World!'.decode('utf8')
'Hello World!'
bytes values are really just sequences, like lists and tuples and strings, but consisting of integer numbers from 0-255:
>>> list('Hello World!'.encode('utf8'))
[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]
Personally, when encrypting, you want to encode and encrypt the resulting bytes.
If all this seems overwhelming or hard to follow, perhaps these articles on Unicode and character encodings can help out:
- What every developer needs to know about Unicode
- Ned Batchelder’s Pragmatic Unicode
- Python’s Unicode HOWTO