Skip to content

Instantly share code, notes, and snippets.

@ktustanowski
Created July 31, 2018 22:28
Show Gist options
  • Save ktustanowski/2c9555edb149134b1b84e8ab4881acdf to your computer and use it in GitHub Desktop.
Save ktustanowski/2c9555edb149134b1b84e8ab4881acdf to your computer and use it in GitHub Desktop.
struct Atbash: Cipher {
private let alphabet = Alphabet.letters
func encrypt(_ text: String) -> String {
var output = [Character]()
for character in text {
if character != " " {
guard let index = alphabet.index(of: character) else { continue }
output.append(alphabet[alphabet.count - index - 1])
} else {
output.append(" ")
}
}
return String(output)
}
func decrypt(_ text: String) -> String {
return encrypt(text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment