-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathsol3.cpp
61 lines (48 loc) · 1.3 KB
/
sol3.cpp
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
#include <cstdio>
#include <cstdint>
uint64_t poly = 0xC96C5795D7870F42;
uint64_t table[256];
void generate_table()
{
for(int i=0; i<256; ++i)
{
uint64_t crc = i;
for(unsigned int j=0; j<8; ++j)
{
// is current coefficient set?
if(crc & 1)
{
// yes, then assume it gets zero'd (by implied x^64 coefficient of dividend)
crc >>= 1;
// and add rest of the divisor
crc ^= poly;
}
else
{
// no? then move to next coefficient
crc >>= 1;
}
}
table[i] = crc;
}
}
uint64_t calculate_crc(uint8_t* stream, unsigned int n, uint64_t crc)
{
for(unsigned int i=0; i<n; ++i)
{
uint8_t index = stream[i] ^ crc;
uint64_t lookup = table[index];
crc >>= 8;
crc ^= lookup;
}
return crc;
}
char buf1[100] = ": You probably just want the flag. So here it is: CTF{dZXi----------PIUTYMI}. :";
char buf2[] = ": You probably just want the flag. So here it is: CTF{dZXi\xff\x9a\xc3\x25\x99\xee\xb2\x41--PIUTYMI}. :";
uint64_t wantcrc = 0x30d498cbfb871112;
int main() {
generate_table();
// Set dashes, so that:
// wantcrc == calculate_crc(buf1, 80, 0);
printf("%lx\n", calculate_crc((uint8_t*)buf2, 80, 0));
}