
July 29th, 2003, 03:30 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 35
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
XORing string elements?
Hello all,
I'm new to Python and I have a problem that I just can't seem to solve...
Using the sha module I have made a 20-byte string that contains the SHA-1 hash of a file. Now I need to reduce that string a 5-byte string that is a function of the SHA-1 hash. To put it in C++ terms, I'd like to do something like:
unsigned char new_hash[5];
new_hash[0] = sha_hash[0] ^ sha_hash[5] ^ sha_hash[10] ^ sha_hash[15];
new_hash[1] = sha_hash[1] ^ sha_hash[6] ^ sha_hash[11] ^ sha_hash[16];
new_hash[2] = sha_hash[2] ^ sha_hash[7] ^ sha_hash[12] ^ sha_hash[17];
new_hash[3] = sha_hash[3] ^ sha_hash[8] ^ sha_hash[13] ^ sha_hash[18];
new_hash[4] = sha_hash[4] ^ sha_hash[9] ^ sha_hash[14] ^ sha_hash[19];
But XORing only works on ints and longs, and converting any string doesn't rely on its underlying bit pattern (understandably so... e.g., '1' converts to the integer 1, not its underlying bit value 31).
Is this trivial? Any help or ideas would be much appreciated!
Thanks,
- the perfect soup
|