Last active
March 25, 2024 20:13
-
-
Save tomfanning/29d9b1d8577c1393d8a8f1f313e6cf97 to your computer and use it in GitHub Desktop.
APRS passcode generator in C#
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
System.Console.WriteLine(DoHash("mycall")); | |
} | |
static int DoHash(string call) | |
{ | |
string upper = call.ToUpper(); | |
string main = upper.Split('-')[0]; | |
int hash = 0x73e2; | |
char[] chars = main.ToCharArray(); | |
while (chars.Length != 0) | |
{ | |
char? one = shift(ref chars); | |
char? two = shift(ref chars); | |
hash = hash ^ one.Value << 8; | |
if (two != null) | |
{ | |
hash = hash ^ two.Value; | |
} | |
} | |
int result = hash & 0x7fff; | |
return result; | |
} | |
static char? shift(ref char[] chars) | |
{ | |
if (chars.Length == 0) | |
return null; | |
char result = chars[0]; | |
char[] newarr = new char[chars.Length - 1]; | |
for (int i = 1; i < chars.Length; i++) | |
{ | |
newarr[i - 1] = chars[i]; | |
} | |
chars = newarr; | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment