blob: 513ae177fc4557a25fd03b5bce2538b8b6ef62f7 (
plain)
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
|
#include <stdio.h>
#include <stdio.h>
int checksum() {
unsigned int parts[9];
unsigned int sum;
printf("Enter the parts, one per line:\n");
for (int i = 0; i < 9; i++) {
scanf("%X", &parts[i]);
sum += parts[i];
while (sum >> 16)
sum = (sum & 0xffff) + (sum >> 16);
}
return ~sum;
}
int main() {
printf("--- SENDER ---\n");
int sender_checksum = checksum();
printf("\n--- RECV ---\n");
int recv_checksum = checksum();
printf("Sent checksum: %x\n", sender_checksum);
printf("Recieved checksum: %x\n", recv_checksum);
if (sender_checksum == recv_checksum) {
printf("Matching checksums!\n");
return 0;
} else {
printf("Mismatched checksums!\n");
return 0;
}
}
// 00004500 00000073 00000000 00004000 00004011 0000c0a8 00000001 0000c0a8 000000c7
// checksum - ffffb861
// 00004500 0000003c 00001c46 00004000 00004006 0000ac10 00000a63 0000ac10 00000a0c
// checksum - 0000b1e6
|