forked from macton/nintendo-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_08.c
104 lines (86 loc) · 1.64 KB
/
test_08.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "rand_ints.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
encode2_32( uint32_t* a, uint32_t* b )
{
uint64_t a0 = (uint64_t)a[0];
uint64_t a1 = (uint64_t)a[1];
uint64_t c = 0;
for (int i=0;i<32;i++)
{
c ^= (a0 & (1<<i)) * a1;
}
b[0] = (uint32_t)c;
b[1] = (uint32_t)(c >> 32);
}
void
print_32b( uint32_t a )
{
for (int i=31;i>=0;i--)
{
printf("%c",a&(1<<i)?'1':'0');
}
}
int
main( void )
{
int test_count = g_RandIntCount-1;
uint32_t* a = g_RandInts;
uint32_t b0[2];
uint32_t b[2];
int fail_count = 0;
for (int i=0;i<test_count;i++)
{
printf("a 0x%08x 0x%08x ",a[1],a[0]);
print_32b(a[1]);
printf(" ");
print_32b(a[0]);
printf("\n");
b[0] = 0;
b[1] = 0;
encode( &a[i],b,32);
printf("b 0x%08x 0x%08x ",b[1], b[0]);
print_32b(b[1]);
printf(" ");
print_32b(b[0]);
printf("\n");
b0[0] = b[0];
b0[1] = b[1];
b[0] = 0;
b[1] = 0;
encode2_32( &a[i],b);
printf("b' 0x%08x 0x%08x ",b[1], b[0]);
print_32b(b[1]);
printf(" ");
print_32b(b[0]);
if ((b0[0] != b[0]) || (b0[1] != b[1]))
{
printf(" <- FAIL");
fail_count++;
}
printf("\n");
printf("\n");
}
if ( fail_count )
{
printf("FAIL COUNT %d\n",fail_count);
}
else
{
printf("ALL TESTS PASSED!\n");
}
return 0;
}