Created
July 31, 2018 22:28
-
-
Save ktustanowski/2c9555edb149134b1b84e8ab4881acdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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