Re: help tranlating perl expressions




"David Bear" <david.bear@xxxxxxx> wrote in message
news:5452284.reKt6RD0Uf@xxxxxxxxxx

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


.



Relevant Pages

  • Re: UTF-8 / German, Scandinavian letters - is it really this difficult?? Linux & Windows XP
    ... For string literals, with the "coding" declaration, Python will accept ... "coding" declaration to produce a Unicode object which unambiguously ... represents the sequence of characters - ie. something that can be ... > strings and/or gibberished characters in Tk GUI title? ...
    (comp.lang.python)
  • Strange problems with encoding
    ... str = re.sub ... UniCode Error: ASCII decoding error: ordinal not in range ... I played with the python ... about Strings done by python, but somehow i ve missed the clue. ...
    (comp.lang.python)
  • Re: Question on Strings
    ... I just wanted to know how are strings represented in python? ... Python 2.x knows str and unicode - the former a sequence ... Strings are stored as UTF-16 or UTF-32 characters? ...
    (comp.lang.python)
  • Re: A Python newbie ask a simple question
    ... the first character in the user supplied response as strings support ... What is the good book to learn Python? ... and having checked out some of the tutorials so you know ... using the Help Index again with "sequence" (since you will probably ...
    (comp.lang.python)
  • Re: Problem of function calls from map()
    ... 'lines' is a large list of strings each of which is seperated by '\t' ... usually easier to understand as a single gestalt (i.e., ... performance in Python (and other languages, too, but perhaps easier to ... map() isn't much of a win in this case. ...
    (comp.lang.python)