Python Args By Reference
Dan Bishop
danb_83 at yahoo.com
Wed May 11 01:59:53 EDT 2005
ncf wrote:
> As I fail to see how an array could be used in this (my own
> stupidity?), would you have any such example? For reference, I'm
trying
> to translate this: http://www.cr0.net:8040/code/crypto/sha256/
(Inside
> sha256_process).
>
> Once again, thanks for the patience, I'm still picking up on all the
> little tid-bits. :)
def P(arr, x, k):
a, b, c, d, e, f, g, h = arr
temp1 = arr[7] + S3(arr[4]) + F1(*arr[4:7]) + k + x
temp2 = S2(arr[0]) + F0(*arr[:3])
arr[3] += temp1
arr[7] = temp1 + temp2
K = [0x428A2F98, 0x71374491, 0xB5C0FBCF,
0xE9B5DBA5, 0x3956C25B, 0x59F111F1,
0x923F82A4, 0xAB1C5ED5, 0xD807AA98]
...
for i in xrange(9):
P(arr, w[i], K[i])
if i != 8: # don't rotate the last time
arr = [arr[-1]] + arr[:-1] # rotate arr
The last line moves the last element of arr to the beginning (so the
positions are correct for the call to P).
More information about the Python-list
mailing list