Skip to content

Instantly share code, notes, and snippets.

@bdd
Last active January 25, 2024 18:27
Show Gist options
  • Save bdd/f71f15e3dbbb870d24543e15d560bda6 to your computer and use it in GitHub Desktop.
Save bdd/f71f15e3dbbb870d24543e15d560bda6 to your computer and use it in GitHub Desktop.
APRS-IS passcode generator
#!/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