APRS Passcode

The following code was converted from PHP and Python to VB.Net.

Pass the call sign to the function
ex: Passcode = GenPC("K4DNM") ''pass or convert callsign to upper case
converted from http://blog.eagleflint.com/wp-content/2012/05/APRS-IS_Passcode
and https://github.com/PHP-APRS-PASSCODE


	  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
	

Use wisely and only if you are an amateur radio operator.