Python Args By Reference
ncf
nothingcanfulfill at gmail.com
Wed May 11 00:55:30 EDT 2005
Ok, I'm relatively new to python (< 1 year experiance), yet I have had
much experiance with other languages.
I never really looked that deeply in the FAQ -- temporary lapse of
stupidity(?). Thanks for the link, the concept seems to help.
The two issues I am having in grasping all of this are as follows:
1) Being new to Python, terms like mutable and immutable. Although I
have probably dealt with them in other languages, the terms by
themselves are a little confusing, but managable overall, so this issue
isn't so big.
2) LARGELY, my issue is as demonstrated by the following code. I was
trying to accomplish an effect similar to what is possible in C.
(Trying to make a pure-python FIPS-180-2 compliant implementation of
the SHA-256 algorithm for more Python practice and to put into some
code for a *trial* secure protocol.)
Example C Code:
#define P(a,b,c,d,e,f,g,h,x,K) \
{ \
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
temp2 = S2(a) + F0(a,b,c); \
d += temp1; h = temp1 + temp2; \
}
Python Code:
def P(a,b,c,d,e,f,g,h,x,K):
temp1 = h + S3(e) + F1(e,f,g) + K + x
temp2 = S2(a) + F0(a,b,c)
d += temp1; h = temp1 + temp2
The reason why it'd be a pain to implement this by any of the methods
provided in the Python FAQs is that SHA-256 rotates the variable order
in the calls. Example code:
P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
Since I cannot simply do it the way I had originally seen it, would
there be an alternative method to proforming the operations that I am
missing?
Once again, many thanks for your time.
-Wes
More information about the Python-list
mailing list