The permutation cipher model
We implement a permutation cipher model that changes the bit order in the characters of the input message.
Task description
The permutation cipher that we are implementing will perform a bitwise permutation of each byte from the input message. If a symbol comes to the input 31 (00011111), then after applying the permutation table [2, 1, 5, 8, 4, 6, 7, 3] we will get an encrypted character. 62 (00111110).
A model describing this task is given below.:
Hidden behind the permutation blocks are subsystems that carry out
- decomposition of the input symbol into a bit array (block
Integer to Bit Converter), - **permutation of ** bits using a block (block
Permute Matrix), - forming a UInt8 number from a vector of bits (block
Bit to Integer Converter).
The number on the front of the block indicates the set value for initializing the random number generator. When changing this value (field Seed block masks) the order of permutation inside the element is automatically overwritten to the one set by the function shuffle the order of permutation.
Launching the model and analyzing the results
# We will load the model if it is not already open on the canvas.
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["Message"]).value
cipher_text = Int.(collect(model_data["Ciphertext"]).value)
received_message = Int.(collect(model_data["Decoding"]).value)
println( "The sent message: ", source_message )
println( "Encrypted message: ", cipher_text )
println( "Received message: ", received_message )
Decoding the message:
alphabet_dict = Dict( zip( 1:33, "abvgdeezhzieklmnoprstufkhtschshyyyy" ))
print( "The decrypted message: ", join( [alphabet_dict[d] for d in received_message], "" ) )
Conclusion
We have created another basic block for building cryptographic systems – the simplest block for direct and "reverse" bit permutation inside message characters.