There's another option that I haven't seen yet as well, where you use
the translation method for strings.
code
# Build a list where each entry is a character whose value is 3 higher
than its index.
charList = [ chr((x+3) % 256) for x in range(256) ]
transform = ''.join(charList) # Change the
Markus Zeindl wrote:
Hello,
I want to write a simple encrypter, but I've got a problem:
How can I convert characters into integers?
Check this out, you'll like it even more than ord/chr:
import array
def mangle(message):
a = array.array('B')
a.fromstring(message)
On Tue, 2004-12-14 at 18:18, Paul Rubin wrote:
Markus Zeindl [EMAIL PROTECTED] writes:
Now I get every character with a loop:
code
buffer =
for i in range(len(message)):
ch = message[i-1:i]
You mean
ch = message[i]
what you have does the wrong thing when i = 0.
Here is
On Wed, 15 Dec 2004 23:59:13 -0500, Adam DePrince [EMAIL PROTECTED] wrote:
message = [chr( (ord( x ) + 3 )%256) for x in message]
Minor correction:
message = ''.join([chr( (ord( x ) + 3 )%256) for x in message])
--
http://mail.python.org/mailman/listinfo/python-list
On 2004-12-14, Markus Zeindl [EMAIL PROTECTED] wrote:
I want to write a simple encrypter, but I've got a problem:
How can I convert characters into integers?
$ python
Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type help, copyright, credits
Markus Zeindl [EMAIL PROTECTED] writes:
Now I get every character with a loop:
code
buffer =
for i in range(len(message)):
ch = message[i-1:i]
You mean
ch = message[i]
what you have does the wrong thing when i = 0.
Here is the problem. I got a string with one character and I
want
Hello,
I want to write a simple encrypter, but I've got a problem:
How can I convert characters into integers?
I have got a string from the user, for example Hi!.
Now I get every character with a loop:
code
buffer =
for i in range(len(message)):
ch = message[i-1:i]
...
/code
The character is
Grant Edwards wrote:
On 2004-12-14, Markus Zeindl [EMAIL PROTECTED] wrote:
I want to write a simple encrypter, but I've got a problem:
How can I convert characters into integers?
$ python
Python 2.3.4 (#2, Aug 19 2004, 15:49:40)
[GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2
Type help,
Markus Zeindl wrote:
I have got a string from the user, for example Hi!.
Now I get every character with a loop:
code
buffer =
for i in range(len(message)):
ch = message[i-1:i]
for ch in message:
...
is simpler and more idiomatic.
Kent
--
http://mail.python.org/mailman/listinfo/python-list