help tranlating perl expressions
Erik Johnson
ej
Thu Sep 28 13:23:25 EDT 2006
"David Bear" <david.bear at asu.edu> wrote in message
news:5452284.reKt6RD0Uf at teancum...
> my $klen = length($key);
> my $blen = 64;
> my $ipad = chr(0x36)x$blen;
> my $opad = chr(0x5c)x$blen;
>
> I don't know if I ever seen any way in python of created a fixed size
> string. Can anyone show me how to implement the same statements in python?
Certainly, you can create fixed-length strings in python:
>>> n = 7
>>> chr(0x36) * n
'6666666'
> I when python XOR's strings, is it the same as when perl xor's them?
No, XOR is a bitwise operation that does not apply to strings.
>>> 5 ^ 0
5
>>> 5 ^ 0xF
10
>>> 'a' ^ 'b'
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
See also the 'struct' module: http://docs.python.org/lib/module-struct.html
More information about the Python-list
mailing list