From 1e42d783d499da590b0891b14bb3e169651d1dcb Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 11:51:59 +0000 Subject: [PATCH] [Sync Iteration] elixir/rotational-cipher/2 --- .../2/lib/rotational_cipher.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solutions/elixir/rotational-cipher/2/lib/rotational_cipher.ex diff --git a/solutions/elixir/rotational-cipher/2/lib/rotational_cipher.ex b/solutions/elixir/rotational-cipher/2/lib/rotational_cipher.ex new file mode 100644 index 0000000..322dcd9 --- /dev/null +++ b/solutions/elixir/rotational-cipher/2/lib/rotational_cipher.ex @@ -0,0 +1,18 @@ +defmodule RotationalCipher do + @doc """ + Given a plaintext and amount to shift by, return a rotated string. + + Example: + iex> RotationalCipher.rotate("Attack at dawn", 13) + "Nggnpx ng qnja" + """ + @spec rotate(text :: String.t(), shift :: integer) :: String.t() + def rotate(text, shift) do + shift_char = fn + char when char in ?A..?Z -> <> + char when char in ?a..?z -> <> + char -> <> + end + text |> String.to_charlist() |> Enum.map_join(shift_char) + end +end