|
-
Sep 26th, 2001, 06:58 PM
#1
Thread Starter
New Member
encryption source
Can someone explain this small encryption source to me? It's the TEA encryption algorithm which I got from: http://vader.brad.ac.uk/tea/tea.shtml
What does: y += (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
and: z += (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
do?? Also why: delta=0x9E3779B9 ?? Thx!
void encipher(const unsigned long *const v, unsigned long *const w, const unsigned long * const k)
{
register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9,n=32;
while(n-->0)
{
y += (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
sum += delta;
z += (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
}
w[0]=y; w[1]=z;
}
-
Sep 27th, 2001, 05:17 AM
#2
transcendental analytic
I can't say I understood this algoritm well, I could though explain what it does in detail. That is answers to What, not why.
delta is golden ratio ~0.618034*2^32, I am not sure why.
^ stands for bitwise exclusive or (not equal), takes two 32 bit operands and XOR them against each other, each bit independetly according to this scheme:
Xor| 0 1
----------
0 | 0 1
1 | 1 0
& stands for bitwise AND, takes two 32 bit operands and AND each bit independetly against the other. according to this scheme:
And| 0 1
----------
0 | 0 0
1 | 0 1
>> stands for bitshift right, it moves all bits y steps right on x if x>>y; the y hi bits (leftmost) will be filled with 0'es
<< stands for bitshift left, it moves all bits y steps left on x if x<<y; the y low bits (rightmost) will be filled with 0'es
+= assigns and returns sum of y and x to y if y+=x;
+ returns sum of y and x to y if y+x;
z << 4 ^ z >> 5
The 32 bits will be xored like this:
Code:
Left operand
[****00000011111111112222222222333]----
[****45678901234567890123456789012]----
---------[0000000000111111111122222222*****]
---------[0123456789012345678901234567*****]
Right operand
k[sum&3];
k[sum>>11 & 3];
first will take the 3 lowbits (valued 0-7) and retrieve the data at that offset, the second will do the same at bit 12-14 (from right)
sum seems to add up with delta in each loop, so you probably get mixed values at k but there seems to be a point with having the golden rate. Everything is summed up to y resp z, but both affect each other according to second term.
register unsigned long makes sure the compiler allocates the variables in the cpu registers, for optimal performance.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 27th, 2001, 06:58 PM
#3
Thread Starter
New Member
Thanx alot! By the way, whats 0x9E3779B9 in decimal?
-
Sep 28th, 2001, 05:09 AM
#4
Frenzied Member
-
Sep 28th, 2001, 06:39 AM
#5
Thread Starter
New Member
Why is this number important and used in this algorithm? When I change it the encryption doesnt work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|