Re: python number handling - tiny encryption algorithm

2005-11-30 Thread Bernhard Mulder
One systematic, if maybe clumsy way, is to mimic the C arithmetic operations more closely in Python. If you do, for example, a left shift in C, the result is always returned in a certain precision, 64 bits in the example below. In python, no bits are lost, so you have to force the result into t

Re: python number handling - tiny encryption algorithm

2005-11-30 Thread Scott David Daniels
Kinsley Turner wrote: > I'm getting a bit out of my depth porting the 'tiny encryption algorithm' > from C to python > In my version, I end up with hugely long integers, which have obviously > not be constrained into the 4-byte unsigned longs that TEA is expecting. > ... > def teaDecipher(inp

Re: python number handling - tiny encryption algorithm

2005-11-30 Thread Carl Friedrich Bolz
Hi! Kinsley Turner wrote: [snip] > > def teaDecipher(input,key): > y = input[0] > z = input[1] > n = 32 > sum = 0xC6EF3720 > delta=0x9E3779B9 > > while (n > 0): > n -= 1 > z -= (y << 4 ^ y >> 5) + y ^ sum + key[sum>>11 & 3]; > sum -= delta; >

Re: python number handling - tiny encryption algorithm

2005-11-29 Thread Paul Rubin
Kinsley Turner <[EMAIL PROTECTED]> writes: > In my version, I end up with hugely long integers, which have obviously > not be constrained into the 4-byte unsigned longs that TEA is expecting. Yeah, Python promotes to long int now. The simplest way to do the 32-bit arithmetic you need is probably

python number handling - tiny encryption algorithm

2005-11-29 Thread Kinsley Turner
Hey-ho, I'm getting a bit out of my depth porting the 'tiny encryption algorithm' from C to python. Ref: http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm http://www.simonshepherd.supanet.com/source.htm#new_ansi Specifically I don;t know how to handle a C-long block and perform the math