Sha256: 301e256d21a6e17c96658de808797fca41203a3dde0d8910a45921f29b49d021

Contents?: true

Size: 989 Bytes

Versions: 310

Compression:

Stored size: 989 Bytes

Contents

-module(example).

-export([encode/1, decode/1, test_version/0]).

encode(String) ->
    join(chunk(convert(String), 5)).

decode(String) ->
    convert(String).

test_version() ->
    1.

%% 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

310 entries across 310 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/atbash-cipher/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/atbash-cipher/src/example.erl