Last active
December 25, 2018 10:21
-
-
Save dmaidon/92ac9cc223f1d3dcdb0b8dab43968c79 to your computer and use it in GitHub Desktop.
Generate APRS-Is Passcode using VB.Net
This file contains hidden or 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
using System; | |
private static long GenPc(string pc) | |
{ | |
//strip station designators. ex: "-5" Only the real call sign is used | |
int stophere = pc.IndexOf("-"); | |
if (stophere > 0) | |
{ | |
pc = pc.Split('-')[0]; | |
} | |
//'the Hash must be 29666 (non-negotiable) | |
long hash = 29666; | |
for (var j = 1; j <= pc.Length; j++) | |
{ | |
if (Convert.ToBoolean((j % 2))) | |
{ | |
hash = hash ^ (Microsoft.VisualBasic.Strings.Asc(pc.ToUpper().Substring(j - 1, 1)) << 8); | |
} | |
else | |
{ | |
hash = hash ^ Microsoft.VisualBasic.Strings.Asc(pc.ToUpper().Substring(j - 1, 1)); | |
} | |
} | |
//'mask the high bit so that the result is always positive | |
return hash & 65535; | |
} |
This file contains hidden or 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
Private Function GenPC(pc As String) As Long | |
Dim j = 1 | |
//strip station designators. ex: "-5" Only the real call sign is used | |
Dim stophere = InStr(pc, "-") - 1 | |
If stophere > 0 Then | |
pc = pc.Split("-"c)(0) | |
End If | |
//the Hash must be 29666 (non-negotiable) | |
Dim hash As Long = 29666 | |
For j = 1 To pc.Length | |
If CBool((j Mod 2)) Then | |
hash = hash Xor (Asc(Mid(pc, j, 1)) << 8) | |
Else | |
hash = hash Xor Asc(Mid(pc, j, 1)) | |
End If | |
Next | |
//mask the high bit so that the result is always positive | |
GenPC = hash And 65535 | |
End Function |
This file contains hidden or 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
Private Shared Function GenPc(pc As String) As Long | |
'strip station designators. ex: "-5" Only the real call sign is used | |
Dim stophere As Integer = InStr(pc, "-") - 1 | |
If stophere > 0 Then | |
pc = pc.Split("-"c)(0) | |
End If | |
''the Hash must be 29666 (non-negotiable) | |
Dim hash As Long = 29666 | |
For j = 1 To pc.Length | |
If CBool(j Mod 2) Then | |
hash = hash Xor (Asc(Mid(pc.ToUpper(), j, 1)) << 8) | |
Else | |
hash = hash Xor Asc(Mid(pc.ToUpper(), j, 1)) | |
End If | |
Next | |
''mask the high bit so that the result is always positive | |
GenPc = hash And 65535 | |
End Function |
Added C# version of function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cleaned up the code by removing an unneeded parenthesis and converting the callsign to uppercase within the function.