Skip to content

Instantly share code, notes, and snippets.

@robacarp
Forked from benlemasurier/gist:5293789
Created April 2, 2013 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robacarp/5293806 to your computer and use it in GitHub Desktop.
Save robacarp/5293806 to your computer and use it in GitHub Desktop.
short passcode(const char *callsign) {
uint8_t i, len;
short hash = KEY;
char no_ssid[10], *p1 = no_ssid, *ptr = no_ssid;
// remove SSID
while((*callsign != '-') && (*callsign != '\0')) *p1++ = toupper((int) (*callsign++));
*p1 = '\0';
i = 0;
len = strlen(no_ssid);
while(i < len) {
hash ^= (unsigned char) (*ptr++) << 8; // high byte
hash ^= (*ptr++); // lower byte
i+=2;
}
return (short) (hash & 0x7fff); // force positive value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment