The permutation cipher model¶
Let's implement a model of a permutation cipher that changes the order of bits in the characters of the input message.
Problem description¶
The permutation cipher we are implementing will perform bit-for-bit permutation of each byte from the input message. If the input is 31 (00011111
), then after applying the permutation table [2, 1, 5, 8, 4, 6, 7, 3]
we will get the encrypted character 62 (00111110
).
A model describing this task is given below:
Behind the permutation blocks are hidden subsystems that perform
- decomposition of the input symbol into a bit array (block
Integer to Bit Converter
), - permutation of bits by means of block (block
Permute Matrix
), - formation of UInt8 number from bit vector (block
Bit to Integer Converter
).
The number on the block face indicates the set value for initialising the random number generator. When this value is changed (field Seed
of the block mask), the permutation order within the element is automatically overwritten by the permutation order specified by the function shuffle
.
Running the model and analysing the results¶
# Загрузим модель, если она еще не открыта на холсте
if "permutation_cipher_model" ∉ getfield.(engee.get_all_models(), :name)
engee.load( "$(@__DIR__)/permutation_cipher_model.engee");
end
model_data = engee.run( "permutation_cipher_model" );
Let's see what values passed through each of the communication lines during the simulation:
source_message = collect(model_data["Сообщение"]).value
cipher_text = Int.(collect(model_data["Шифротекст"]).value)
received_message = Int.(collect(model_data["Расшифровка"]).value)
println( "Отправленное сообщение: ", source_message )
println( "Зашифрованное сообщение: ", cipher_text )
println( "Полученное сообщение: ", received_message )
Decode the message:
alphabet_dict = Dict( zip( 1:33, "абвгдеёжзиёклмнопрстуфхцчшщъыьэюя" ))
print( "Расшифрованное сообщение: ", join( [alphabet_dict[d] for d in received_message], "" ) )
Conclusion¶
We have created another basic block for building cryptographic systems - the simplest block for forward and "backward" permutation of bits within message symbols.