The gamut
Gamming is the process of superimposing a cipher's gamut on open data according to a certain law.
A gamma cipher is a pseudorandom binary sequence generated by a given algorithm for encrypting open data and decrypting encrypted data. This encryption method is non-breakable if the length of the input message is equal to the length of the gamut.
The essence of the method lies in the fact that the characters of the encrypted text are sequentially combined with the characters of a special sequence called the gamut.
The procedure for applying the scale is carried out in the following ways:
- The characters of the source text and gamma are replaced by equivalent numbers, which are then added modulo k, where k is the number of characters in the alphabet, i.e.: Ri=(Si+G)mod(k–1), where Ri, Si, G are the characters of the ciphertext, source text, and gamma, respectively.
- The symbols of the source text and gamma are represented as binary code, and then the corresponding digits are added modulo 2. Instead of addition modulo 2, other logical functions can be used in the gamut.
Now let's look at the algorithm we implemented. The code is shown below.
Since this operation itself is reversible, the encryption and decryption functions are identical.
# Implementation of the bitxor function
bitxor(a::Integer, b::Integer) = a ⊻ b
# Defining input values
input_string = collect("The exhibitor")
Game = collect("Engee")
# Alignment of the scale relative to the input word
Game = repeat([Game], inner=(ceil(Int, length(input_string) / length(Game))))
Game = collect(Iterators.flatten(Game))
# Coding
output = map(x -> bitxor(Int(x[1]), Int(x[2])), zip(input_string, Game[1:length(input_string)]))
# Printing the encoding result
println("Encoded string:")
for ch in output
print(Char(ch))
end
# Decoding
input_string2 = output
# Algorithm
output2 = map(x -> bitxor(Int(x[1]), Int(x[2])), zip(input_string2, Game[1:length(input_string2)]))
# Printing the decoding result
println("\The decoded string:")
for ch in output2
print(Char(ch))
end
Conclusion
In this demonstration, we made sure that the gamut formula works correctly.