help tranlating perl expressions
- From: David Bear <david.bear@xxxxxxx>
- Date: Thu, 28 Sep 2006 10:09:52 -0700
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 --
.
- Follow-Ups:
- Re: help tranlating perl expressions
- From: Fredrik Lundh
- Re: help tranlating perl expressions
- From: Erik Johnson
- Re: help tranlating perl expressions
- Prev by Date: Re: Questions on Using Python to Teach Data Structures and Algorithms
- Next by Date: Re: Questions on Using Python to Teach Data Structures and Algorithms
- Previous by thread: using the email module
- Next by thread: Re: help tranlating perl expressions
- Index(es):
Relevant Pages
|