#include #include #define rot( x, k ) (((x)<<(k))|((x)>>(32-(k)))) typedef unsigned int u4; struct triple { u4 a, b, c; }; int main() { const u4 rot1 = 7, rot2 = 14, rot3 = 29; triple tgt, pre; tgt.a = 0x12345678; tgt.b = 0x87654321; tgt.c = 0xabcdef30; pre.a = 0xabababab; pre.b = 0xdededede; pre.c = 0xdeadbeef; for ( u4 test = 0; test < 0xffffffff; test++ ) { u4 data0 = ( ( tgt.a ^ rot( ( ( tgt.b ^ rot( ( tgt.c - ( pre.c ^ rot( test, rot1 ) ) ), rot3 ) ) - pre.b ), rot2 ) ) - pre.a ); if ( data0 == test ) { u4 data2 = ( tgt.c - ( pre.c ^ rot( data0, rot1 ) ) ); u4 data1 = ( tgt.b ^ rot( data2, rot3 ) ) - pre.b; triple post = pre; u4 t = data0; post.a += t; t = rot(t, rot1); post.c ^= t; t = data1; post.b += t; t = rot(t, rot2); post.a ^= t; t = data2; post.c += t; t = rot(t, rot3); post.b ^= t; printf( "target: %x %x %x, result: %x %x %x (data: %x %x %x)\n", tgt.a, tgt.b, tgt.c, post.a, post.b, post.c, data0, data1, data2 ); } } return ( 0 ); } /* t = data[0]; a += t; t = rotate(t, const1); c ^= t; t = data[1]; b += t; t = rotate(t, const2); a ^= t; t = data[2]; c += t; t = rotate(t, const3); b ^= t; data[0] = ( A ^ rotate(data[1],rot2) ) - a data[1] = ( B ^ rotate(data[2],rot3) ) - b data[2] = ( C - ( c ^ rotate(data[0],rot1) ) ) */