X-Git-Url: https://code.kerkeslager.com/?p=sandbox;a=blobdiff_plain;f=cryptopals%2F01.03%2Fhex.erl;fp=cryptopals%2F01.03%2Fhex.erl;h=0000000000000000000000000000000000000000;hp=417503ccc59229b196d63309a7a950c7050f9df1;hb=b37c633b0ba51e497920762fa2eb4d732ebca291;hpb=545381e1397107d4ab00d2e54d85d3e11d98e4f1 diff --git a/cryptopals/01.03/hex.erl b/cryptopals/01.03/hex.erl deleted file mode 100644 index 417503c..0000000 --- a/cryptopals/01.03/hex.erl +++ /dev/null @@ -1,22 +0,0 @@ --module(hex). --export([decode/1,encode/1,fixed_xor/2,single_byte_xor/2]). - -data_in_pairs([]) -> []; -data_in_pairs([C1,C2|Tail]) -> [ [C1] ++ [C2] | data_in_pairs(Tail) ]. - -int_to_hex(N) when N < 256 -> [hex(N div 16), hex(N rem 16)]. - -hex(N) when (0 =< N) and (N < 10) -> $0 + N; -hex(N) when (10 =< N) and (N < 16) -> $a + (N-10). - -decode(Data) -> [ list_to_integer(P,16) || P <- data_in_pairs(Data) ]. -encode(L) -> string:join(lists:map(fun(X) -> int_to_hex(X) end, L), ""). - -fixed_xor(Data1,Data2) -> - lists:zipwith( - fun(P1,P2) -> P1 bxor P2 end, - Data1, - Data2). - -single_byte_xor(Byte, Data) -> - fixed_xor(lists:duplicate(length(Data),Byte),Data).