37 lines
549 B
Go
37 lines
549 B
Go
package atbash
|
|
|
|
import "strings"
|
|
|
|
func Atbash(s string) string {
|
|
s = strings.ToLower(s)
|
|
var v []byte
|
|
var b, iter int
|
|
for i := range s {
|
|
sv := int(s[i])
|
|
switch {
|
|
case sv < 48:
|
|
continue
|
|
case sv >= 48 && sv <= 57:
|
|
b = sv
|
|
case sv < 109:
|
|
b = 110 + (109 - sv)
|
|
case sv == 109:
|
|
b = 110
|
|
case sv == 110:
|
|
b = 109
|
|
case sv > 110:
|
|
b = 109 - (sv - 110)
|
|
}
|
|
v = append(v, byte(b))
|
|
iter++
|
|
if iter == 5 {
|
|
v = append(v, ' ')
|
|
iter = 0
|
|
}
|
|
}
|
|
if iter == 0 {
|
|
return string(v)[:len(string(v))-1]
|
|
}
|
|
return string(v)
|
|
}
|