Skip to content

Instantly share code, notes, and snippets.

@tomfanning
Last active March 25, 2024 20:13
Show Gist options
  • Save tomfanning/29d9b1d8577c1393d8a8f1f313e6cf97 to your computer and use it in GitHub Desktop.
Save tomfanning/29d9b1d8577c1393d8a8f1f313e6cf97 to your computer and use it in GitHub Desktop.
APRS passcode generator in C#
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