Sha256: 8a772fd6bd05a34f38b885b92c6c1978c12817e811ff34cb3aeb3b3175b70b02
Contents?: true
Size: 710 Bytes
Versions: 179
Compression:
Stored size: 710 Bytes
Contents
defmodule Atbash do @key Enum.zip(?a..?z, ?z..?a) |> Enum.into(%{}) @doc """ Encode a given plaintext to the corresponding ciphertext ## Examples iex> Atbash.encode("completely insecure") "xlnko vgvob rmhvx fiv" """ def encode(plaintext) do plaintext |> normalize |> cipher |> chunk |> Enum.join(" ") end defp normalize(input) do Regex.replace(~r{\W}, String.downcase(input), "") end defp cipher(plaintext) do plaintext |> String.to_char_list |> Enum.map(&convert/1) |> List.to_string end defp convert(character) do Map.get(@key, character, character) end defp chunk(input) do Regex.scan(~r(.{1,5}), input) |> List.flatten end end
Version data entries
179 entries across 179 versions & 1 rubygems