Advertisement
dmaidon

APRS -Is Passcode Generator

Nov 12th, 2020
1,553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.00 KB | None | 0 0
  1. The following code was converted from PHP and Python to VB.Net.
  2. Pass the call sign to the function
  3. ex: Passcode = GenPC("K4DNM") ''pass or convert callsign to upper case
  4. converted from http://blog.eagleflint.com/wp-content/2012/05/APRS-IS_Passcode
  5. and https://github.com/PHP-APRS-PASSCODE
  6.  
  7.  
  8. Private Shared Function GenPc(pc As String) As Long
  9.         'strip station designators. ex: "-5"  Only the real call sign is used
  10.         Dim stophere As Integer = InStr(pc, "-") - 1
  11.         If stophere > 0 Then
  12.             pc = pc.Split("-"c)(0)
  13.         End If
  14.  
  15.         ''the Hash must be 29666 (non-negotiable)
  16.         Dim hash As Long = 29666
  17.  
  18.         For j = 1 To pc.Length
  19.             If CBool(j Mod 2) Then
  20.                 hash = hash Xor (Asc(Mid(pc.ToUpper(), j, 1)) << 8)
  21.             Else
  22.                 hash = hash Xor Asc(Mid(pc.ToUpper(), j, 1))
  23.             End If
  24.         Next
  25.  
  26.         ''mask the high bit so that the result is always positive
  27.         GenPc = hash And 65535
  28.     End Function
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement