N
N
Nikolaanastasiia2020-06-13 21:21:52
Python
Nikolaanastasiia, 2020-06-13 21:21:52

How to do decryption? First there was a series of letters, the encoded word was deciphered, but how to do it back?

The code:

spoiler
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))



5ee51922b6918901878668.png

5ee5192b4b732255217465.png5ee51a7cb116e349321942.png
import sympy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-13
@Nikolaanastasiia

x \u003d K -1 y?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question