Sha256: 019f3d36a4e87dc0029f94ea5e02660e8c5ab5d80b4daa562402033f0a902899
Contents?: true
Size: 953 Bytes
Versions: 84
Compression:
Stored size: 953 Bytes
Contents
-module(atbash_cipher). -export([encode/1, decode/1]). encode(String) -> join(chunk(convert(String), 5)). decode(String) -> convert(String). %% Basic conversion routines convert(String) -> lists:filtermap(fun encode_char/1, String). encode_char(C) when C >= $A, C =< $Z -> %% shift to lower-case {true, $Z - C + $a}; encode_char(C) when C >= $a, C =< $z -> {true, $z - C + $a}; encode_char(C) when C >= $0, C =< $9 -> {true, C}; encode_char(_C) -> false. %% %% Functions for converting to word chunks of 5 characters join(Lists) -> string:join(Lists, " "). chunk(String, N) -> lists:reverse(chunk( lists:split(min(length(String), N), String), [], N)). chunk({Last, []}, Accum, _N) -> [Last] ++ Accum; chunk({Next, Remainder}, Accum, N) -> chunk( lists:split(min(length(Remainder), N), Remainder), [Next] ++ Accum, N). %%
Version data entries
84 entries across 84 versions & 1 rubygems