1 
2 #include <string.h>
3 #include <ctype.h>
4 
5 #include "passcode.h"
6 
7 /* As of April 11 2000 Steve Dimse has released this code to the open
8  * source aprs community
9  *
10  * (from aprsd sources)
11  */
12 
13 #define kKey 0x73e2		// This is the key for the data
14 
aprs_passcode(const char * theCall)15 short aprs_passcode(const char* theCall)
16 {
17 	char rootCall[10];	// need to copy call to remove ssid from parse
18 	char *p1 = rootCall;
19 
20 	while ((*theCall != '-') && (*theCall != 0) && (p1 < rootCall + 9))
21 		*p1++ = toupper(*theCall++);
22 
23 	*p1 = 0;
24 
25 	short hash = kKey;		// Initialize with the key value
26 	short i = 0;
27 	short len = strlen(rootCall);
28 	char *ptr = rootCall;
29 
30 	while (i < len) {		// Loop through the string two bytes at a time
31 		hash ^= (*ptr++)<<8;	// xor high byte with accumulated hash
32 		hash ^= (*ptr++);	// xor low byte with accumulated hash
33 		i += 2;
34 	}
35 
36 	return hash & 0x7fff;		// mask off the high bit so number is always positive
37 }
38 
39