Answer the question
In order to leave comments, you need to log in
How to do decryption? First there was a series of letters, the encoded word was deciphered, but how to do it back?
The code:
def ciphermaker(string, matrix, n):
"""Функция для шифрования блока"""
y = ""
for i in range(n):
k = 0
for j in range(n):
k = k + matrix[i * n + j] * findindex(string[j])
k = k % 28
y = y + INDEX[k]
return y
def findindex(t):
"""Короткая функция получения индекса элемента"""
return INDEX.index(t)
def cipher(string, matrix, n):
"""Основная функция, которая делит всю строку на блоки по n и отправляет на шифровку"""
p = ""
y = ""
for x in string:
p = p + x
if len(p) == n:
y = y + ciphermaker(p, matrix, n)
p = ""
return y
INDEX = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " ", "-"] # Алфавит
X = "live long and prosper" # Текст для шифрования
N = 3 # Размер матрицы
M = sympy.Matrix() # Матрица для шифрования - ключ
print(cipher(X, M, N))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question