30 lines
463 B
Go
30 lines
463 B
Go
package aprs
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
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 {
|
|
return 0, fmt.Errorf("aprs: invalid base-91 encoding char %q (%d)", c, c)
|
|
}
|
|
|
|
n *= 91
|
|
n += int(c) - 33
|
|
}
|
|
return
|
|
}
|
|
|
|
func base91Encode(n int) string {
|
|
var s []string
|
|
for n > 0 {
|
|
c := n % 91
|
|
n /= 91
|
|
s = append([]string{string(byte(c) + 33)}, s...)
|
|
}
|
|
return strings.Join(s, "")
|
|
}
|