Initial import
This commit is contained in:
29
protocol/aprs/base91.go
Normal file
29
protocol/aprs/base91.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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, "")
|
||||
}
|
||||
Reference in New Issue
Block a user