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.
# Реализация функции bitxor
bitxor(a::Integer, b::Integer) = a ⊻ b
# Определение входных значений
input_string = collect("Экспонента")
Game = collect("Engee")
# Выравнивание гаммы относительно входного слова
Game = repeat([Game], inner=(ceil(Int, length(input_string) / length(Game))))
Game = collect(Iterators.flatten(Game))
# Кодирование
output = map(x -> bitxor(Int(x[1]), Int(x[2])), zip(input_string, Game[1:length(input_string)]))
# Печать результата кодирования
println("Закодированная строка:")
for ch in output
print(Char(ch))
end
# Декодирование
input_string2 = output
# Алгоритм
output2 = map(x -> bitxor(Int(x[1]), Int(x[2])), zip(input_string2, Game[1:length(input_string2)]))
# Печать результата декодирования
println("\nДекодированная строка:")
for ch in output2
print(Char(ch))
end
Conclusion
In this demonstration, we made sure that the gamut formula works correctly.