Last active
January 25, 2024 18:27
-
-
Save bdd/f71f15e3dbbb870d24543e15d560bda6 to your computer and use it in GitHub Desktop.
APRS-IS passcode generator
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
#!/usr/bin/env python3 | |
from itertools import zip_longest | |
from functools import reduce | |
def code(callsign): | |
"""Return APRS-IS passcode for callsign | |
Based on aprsc's implementation at https://git.io/vrGXL | |
""" | |
def xor_tuple(t1, t2): | |
return (x ^ y for x, y in zip(t1, t2)) | |
seed = (0x73, 0xe2) | |
ordinals = iter((ord(c) for c in callsign.upper())) | |
iterable = zip_longest(ordinals, ordinals, fillvalue=0) | |
hi_byte, lo_byte = reduce(xor_tuple, iterable, seed) | |
return ((hi_byte & 0x7f) << 8) + lo_byte |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment