summaryrefslogtreecommitdiff
path: root/go/atbash-cipher/atbash_cipher.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-30 02:05:53 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-30 02:05:53 +0200
commit89539daca2be78d19e36e0f5b952d3ec259c8e78 (patch)
treec53d21d07c628c0d48c056cca40df648fe79bfe2 /go/atbash-cipher/atbash_cipher.go
parentbfb81139b65cd99b4a231e42a810214388194ec7 (diff)
Solve Atbash
Diffstat (limited to 'go/atbash-cipher/atbash_cipher.go')
-rw-r--r--go/atbash-cipher/atbash_cipher.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/go/atbash-cipher/atbash_cipher.go b/go/atbash-cipher/atbash_cipher.go
new file mode 100644
index 0000000..34f94f0
--- /dev/null
+++ b/go/atbash-cipher/atbash_cipher.go
@@ -0,0 +1,23 @@
+package atbash
+
+import "unicode"
+
+func Atbash(s string) string {
+ r := []rune{}
+ for _, v := range s {
+ switch {
+ case unicode.IsLetter(v):
+ r = append(r, 'z'-unicode.ToLower(v)+'a')
+ case unicode.IsNumber(v):
+ r = append(r, v)
+ }
+ }
+ ret := []rune{}
+ for i, v := range r {
+ ret = append(ret, v)
+ if (i+1)%5 == 0 && i != len(r)-1 {
+ ret = append(ret, ' ')
+ }
+ }
+ return string(ret)
+}