Engee documentation
Notebook

Gamification

Gamification is the process of imposing, according to a certain law, the gamut of a cipher on public data.

A cipher gamma is a pseudo-random binary sequence produced according to a specified algorithm to encrypt the public data and decrypt the encrypted data. This encryption method is unbreakable if the length of the input message is equal to the length of the gamma.

The essence of the method is that the characters of the ciphertext are sequentially added to the characters of some special sequence, which is called gamma.

The gamma imposition procedure is carried out in the following ways:

  1. The characters of the source text and gamma are replaced by equivalent digits, which are then added modulo k, where k is the number of characters in the alphabet, ie: Ri=(Si+G)mod(k-1) where Ri, Si, G are the characters of the ciphertext, source text and gamma respectively.
  2. The source code and gamma characters are represented as a binary code and then the corresponding digits are added modulo 2. Instead of modulo 2 addition, other logical functions can be used in gamming. Now let us consider the algorithm we have implemented. The code is presented below.

Since this operation itself is reversible, the encryption and decryption functions are identical.

In [ ]:
# Реализация функции bitxor
bitxor(a::Integer, b::Integer) = a  b
Out[0]:
bitxor (generic function with 1 method)
In [ ]:
# Определение входных значений
input_string = collect("Экспонента")
Game = collect("Engee")

# Выравнивание гаммы относительно входного слова
Game = repeat([Game], inner=(ceil(Int, length(input_string) / length(Game))))
Game = collect(Iterators.flatten(Game))
Out[0]:
10-element Vector{Char}:
 'E': ASCII/Unicode U+0045 (category Lu: Letter, uppercase)
 'n': ASCII/Unicode U+006E (category Ll: Letter, lowercase)
 'g': ASCII/Unicode U+0067 (category Ll: Letter, lowercase)
 'e': ASCII/Unicode U+0065 (category Ll: Letter, lowercase)
 'e': ASCII/Unicode U+0065 (category Ll: Letter, lowercase)
 'E': ASCII/Unicode U+0045 (category Lu: Letter, uppercase)
 'n': ASCII/Unicode U+006E (category Ll: Letter, lowercase)
 'g': ASCII/Unicode U+0067 (category Ll: Letter, lowercase)
 'e': ASCII/Unicode U+0065 (category Ll: Letter, lowercase)
 'e': ASCII/Unicode U+0065 (category Ll: Letter, lowercase)
In [ ]:
# Кодирование
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 have verified that the gamma formula works correctly.