/gorp/ challenge #2: serialme
Name:
Anonymous
2008-02-29 10:43
/* /gorp/ challenge #2: serialme
2008-02-29
Requirements: c99 compiler, ASCII or compatible character set.
Example: gcc serialme.c -O2 -Wall -Wextra -std=c99 -oserialme
It's source so people can't whine it doesn't run on their SPARC with Plan9.
Everyone is allowed to use this in any way. */
#include <stdio.h>
#include <stdint.h>
#define BUFSIZE 8
static int hexdigit_to_int(char hex)
{
if(hex >= '0' && hex <= '9')
return hex - '0';
if(hex >= 'A' && hex <= 'F')
return hex - 'A' + 10;
return -1;
}
int main(int argc, char** argv)
{
unsigned buffer[BUFSIZE];
if(argc != 2)
{
puts("Usage: serialme [serial]");
return 0;
}
char *input = argv[1];
for(unsigned i = 0; i < BUFSIZE; i++)
{
int low, high;
high = hexdigit_to_int(*input++);
if(high == -1)
return 1;
low = hexdigit_to_int(*input++);
if(low == -1)
return 1;
buffer[i] = (high << 4) | low;
}
if(*input)
return 1;
const unsigned checkvalues[BUFSIZE][BUFSIZE+1] =
{{195, 162, 208, 7, 39, 60, 55, 112, 121261},
{177, 37, 168, 214, 104, 81, 120, 111, 116729},
{ 49, 39, 221, 134, 241, 211, 110, 104, 152301},
{ 65, 56, 253, 18, 94, 116, 57, 183, 115139},
{152, 54, 137, 5, 150, 182, 195, 179, 148075},
{219, 100, 130, 195, 125, 197, 244, 184, 175270},
{123, 223, 21, 203, 140, 26, 112, 84, 116269},
{171, 163, 212, 44, 20, 125, 214, 84, 139951}};
for(unsigned i = 0; i < BUFSIZE; i++)
{
unsigned sum = 0;
for(unsigned j = 0; j < BUFSIZE; j++)
sum += checkvalues[i][j] * buffer[j];
if(sum != checkvalues[i][BUFSIZE])
return 1;
}
printf("Congrats, please go to http://ln-s.net/");
putchar(buffer[0] ^ buffer[4]);
putchar(buffer[1] ^ buffer[5]);
putchar(buffer[2] ^ buffer[6]);
putchar(buffer[3] ^ buffer[7]);
puts(" for your prize.");
return 0;
}
Name:
Anonymous
2008-02-29 17:21
http://ln-s.net/1c7D
you made me install matlab for this?
Newer Posts