32 lines
509 B
Go
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])
|
|
}
|