Engee 文档
Notebook

范围

封堵是根据一定规律将密码的色域叠加在开放数据上的过程。

Gamma密码是由给定算法生成的伪随机二进制序列,用于加密开放数据和解密加密数据。 如果输入消息的长度等于色域的长度,则此加密方法是不可中断的。

该方法的实质在于这样一个事实,即加密文本的字符顺序地与称为色域的特殊序列的字符组合。

应用量表的程序通过以下方式进行:

  1. 源文本和gamma的字符用等效数字替换,然后将其加模k,其中k是字母表中的字符数,即:Ri=(Si+G)mod(k–1),其中Ri,Si,G分别是密文,源文本和gamma的字符。
  2. 源文本和伽玛的符号表示为二进制代码,然后将相应的数字加模2。 代替加法模2,可以在色域中使用其他逻辑函数。
    现在让我们来看看我们实现的算法。 代码如下所示。

由于此操作本身是可逆的,因此加密和解密功能是相同的。

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
Закодированная строка:
ѨєЦњћѸћњЧѕ
Декодированная строка:
Экспонента

结论

在本演示中,我们确保色域公式正常工作。