Other Elixir solutions.
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
end
end
Other Roc solutions.
module [rotate]
rotate : Str, U8 -> Str
rotate = \text, shiftKey ->
text
|> Str.toUtf8
|> List.map \c -> rotateChar c shiftKey
|> Str.fromUtf8
|> Result.withDefault ""
rotateChar : U8, U8 -> U8
rotateChar = \char, shiftKey ->
if char >= 'A' && char <= 'Z' then
(char - 'A' + shiftKey) % 26 + 'A'
else if char >= 'a' && char <= 'z' then
(char - 'a' + shiftKey) % 26 + 'a'
else
char