Files
ham/protocol/aprs/base91.go
maze 63040a44b3
Some checks failed
Run tests / test (1.25) (push) Failing after 1m37s
Run tests / test (stable) (push) Failing after 1m37s
protocol/aprs: refactored
2026-03-02 22:28:17 +01:00

32 lines
509 B
Go

package aprs
import (
"fmt"
"slices"
)
func base91Decode(s string) (n int, err error) {
for i, l := 0, len(s); i < l; i++ {
c := s[i]
if c < 33 || c > 122 {
// panic(fmt.Sprintf("aprs: invalid base-91 encoding char %q (%d)", c, c))
return 0, fmt.Errorf("aprs: invalid base-91 encoding char %q (%d)", c, c)
}
n *= 91
n += int(c) - 33
}
return
}
func base91Encode(b []byte, n int) {
i := 0
for n > 1 {
x := n % 91
n /= 91
b[i] = byte(x) + 33
i++
}
slices.Reverse(b[:i])
}