Created
February 1, 2014 04:35
-
-
Save mariotaku/8748026 to your computer and use it in GitHub Desktop.
wps checksum tool
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> | |
unsigned int wps_pin_checksum(unsigned int pin); | |
int main(int argc, char *argv[]) | |
{ | |
int pin; | |
if ((argc == 2 && sscanf(argv[1], "%i", &pin)) || fscanf(stdin, "%i", &pin)) | |
{ | |
if (pin > 9999999) | |
{ | |
goto error; | |
} | |
printf("%07d%d\n", pin, wps_pin_checksum(pin)); | |
return 0; | |
} | |
else | |
{ | |
goto error; | |
} | |
error: | |
{ | |
fprintf(stderr, "Invalid WPS Pin.\n"); | |
return -1; | |
} | |
} | |
/** | |
* wps_pin_checksum - Compute PIN checksum | |
* @pin: Seven digit PIN (i.e., eight digit PIN without the checksum digit) | |
* Returns: Checksum digit | |
*/ | |
unsigned int wps_pin_checksum(unsigned int pin) | |
{ | |
unsigned int accum = 0; | |
while (pin) { | |
accum += 3 * (pin % 10); | |
pin /= 10; | |
accum += pin % 10; | |
pin /= 10; | |
} | |
return (10 - accum % 10) % 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment