-
-
Save ikr7/70bbf6c56a1e54010782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define ID_LEN 12 | |
int main() { | |
char id[ID_LEN] = { | |
0x30, 0x31, 0x30, 0x30, | |
0x30, 0x37, 0x33, 0x34, | |
0x45, 0x30, 0x44, 0x32 | |
}; | |
unsigned int check; | |
char check_c[3] = {'\0'}; | |
sprintf(check_c, "%c%c", id[10], id[11]); | |
sscanf(check_c, "%x", &check); | |
unsigned int sum = 0; | |
for (int i = 0; i < ID_LEN - 2; i += 2){ | |
unsigned int sum_t = 0; | |
char sum_c[3] = {'\0'}; | |
sprintf(sum_c, "%c%c", id[i], id[i + 1]); | |
sscanf(sum_c, "%x", &sum_t); | |
sum ^= sum_t; | |
} | |
if (check == sum) { | |
printf("OK\n"); | |
} else { | |
printf("NG\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment