From 7fb5559c7853a8fbd7f75df73105ba49c36c319e Mon Sep 17 00:00:00 2001 From: ricmaps Date: Mon, 15 Jun 2026 23:51:33 -0300 Subject: [PATCH] Add Rot13 in Elixir --- archive/e/elixir/rot13.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 archive/e/elixir/rot13.ex diff --git a/archive/e/elixir/rot13.ex b/archive/e/elixir/rot13.ex new file mode 100644 index 000000000..91fa874c9 --- /dev/null +++ b/archive/e/elixir/rot13.ex @@ -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