forked from macton/nintendo-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_04.c
58 lines (48 loc) · 862 Bytes
/
test_04.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdint.h>
#include <stdio.h>
#include <string.h>
void
encode( uint32_t* a, uint32_t* b, int size )
{
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
b[(i + j) / 32] ^= ( (a[i / 32] >> (i % 32)) & (a[j / 32 + size / 32] >> (j % 32)) & 1 ) << ((i + j) % 32); // Magic centaurian operation
}
}
}
void
print_32b( uint32_t a )
{
for (int i=31;i>=0;i--)
{
printf("%c",a&(1<<i)?'1':'0');
}
}
int
main( void )
{
uint32_t a[ 2 ];
uint32_t b[ 2 ];
for (int i=0;i<32;i++)
{
a[0] = 0xffffffff;
a[1] = 1<<i;
b[0] = 0;
b[1] = 0;
encode( a,b,32 );
printf("a ");
print_32b(a[1]);
printf(" ");
print_32b(a[0]);
printf("\n");
printf("b ");
print_32b(b[1]);
printf(" ");
print_32b(b[0]);
printf("\n");
printf("\n");
}
return 0;
}