From 89539daca2be78d19e36e0f5b952d3ec259c8e78 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 30 Aug 2016 02:05:53 +0200 Subject: Solve Atbash --- go/atbash-cipher/atbash_cipher.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 go/atbash-cipher/atbash_cipher.go (limited to 'go/atbash-cipher/atbash_cipher.go') 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) +} -- cgit v1.2.3