Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions archive/e/elixir/rot13.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule Rot13 do
@doc """
Returns a string after applying the Rot-13 cypher
"""
@spec rot13(str :: String.t()) :: String.t()
def rot13(str), do: to_charlist(str) |> Enum.map(&rot/1) |> to_string()

defp rot(char) when char in ?a..?z, do: rem(char - ?a + 13, 26) + ?a
defp rot(char) when char in ?A..?Z, do: rem(char - ?A + 13, 26) + ?A
defp rot(char), do: char
end

case System.argv() do
[str] when byte_size(str) > 0 -> Rot13.rot13(str) |> IO.puts()
_ -> IO.puts("Usage: please provide a string to encrypt")
end