Block cipher with custom encoding

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Block cipher with custom encoding


I'm quite new to programming and Erlang as well. I'm trying to implement a block cipher algorithm. My main problem is the mapping of characters to a corresponding integer value. I do know about the representation of strings in lists but my professor asked for a custom encoding of each character. I approached the problem with a map where I assigned numbers to a map, which I'm reading from the filesystem.
I'm using this code to generate the map:

build_map(A) -> {ok,Map} = file:consult(A),

The file I'm consulting looks like this:

This function is used for the generation of an integer for the block which a length of K.

toBlock(Input, K, Map, Result, Length) ->
        if K /= 0 ->
                        Tail = tl(Input),NewK = K - 1, Char = string:slice(Input,0,1), TheChar = maps:get(Char,Map,""), Mult = fastExponentiation(Length,K),
                        toBlock(Tail,NewK,Map,Result + (TheChar * Mult),Length);
                true -> [(Result + maps:get(string:slice(Input,0,1),Map,""))]

But this approach has certain drawbacks as I'm not able to include all characters I need for this map to work. I´d like to cover at least
all printable characters from the latin1 charset. A requirement for the map is, that after the encryption the cipher has to be converted
to text again. So all code-points have to be printable.
The conversion from String to Integer has to be like A * pow(Len,K) where A is the value of the character, Len the length of the map and K the position of the character inside of the block.

Can someone please give me a hint how I could improve my approach?

erlang-questions mailing list
[hidden email]