help tranlating perl expressions



I am trying to translate some perl code to python and I need some advice on
making fixed sized strings. The perl code creates a sha1 signatured using a
key and a 'pad'. It creates fixed sized strings as follows:

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?

Next, it zero-fills a string to a certain size.

if($klen <= $blen) {
$key .= "\0"x($blen-length($key)); #zero-fill to blocksize
} else {
$key = sha1($key); #if longer, pre-hash key
}

Finally it concatenates and xors these strings together like this:

return sha1($key^$opad . sha1($key^$ipad . $data));

I when python XOR's strings, is it the same as when perl xor's them?

--
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
.



Relevant Pages

  • Re: help tranlating perl expressions
    ... > I am trying to translate some perl code to python and I need some ... > advice on making fixed sized strings. ... Python, really, since it's part of the standard library: ... dependencies on the way perl was making the digest. ...
    (comp.lang.python)
  • 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)
  • 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)
  • Re: Seeking regex optimizer
    ... Note that the Python regex engine will consider each candidate in Paddy's solution left to right until it gets a match or reaches the end. ... This is worst-case Owhere N is the total of the lengths of all the strings in your list. ... "sx.matchyields a SRE_Match object" ... ... I would have thought the way to approach this would be a simple character-by-character tree/trie-driven lookup. ...
    (comp.lang.python)