Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tekst_jawny = "Najlepsze kasztany rosna na placu pigale latem"
- # key = "okon"
- def create_key_matrix(tekst_jawny):
- key = tekst_jawny[0:4].lower()
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- rows, cols = len(key) / 2, len(key) / 2
- index = 0
- matrix_key = [[0 for _ in range(int(cols))] for _ in range(int(rows))]
- for i in range(int(rows)):
- for j in range(int(cols)):
- matrix_key[i][j] = alphabet.index(key[index])
- index += 1
- return matrix_key
- def create_cipher_matrix(tekst_jawny):
- matrix = create_key_matrix(tekst_jawny)
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- encrypted_tekst = ""
- tekst_jawny = tekst_jawny.replace(" ", "").lower()
- index = 0
- print(len(tekst_jawny))
- while index + 1 < len(tekst_jawny):
- j = 0
- for row in range(2):
- print(row)
- a = alphabet.index(tekst_jawny[index])
- b = alphabet.index(tekst_jawny[index + 1])
- value = ((matrix[row][j] * a) + (matrix[row][j + 1] * b)) % 26
- print(
- f"{matrix[row][j]} * {a} + {matrix[row][j+1]} * {b} % 26 = {value} litera a = {tekst_jawny[index]} litera b = {tekst_jawny[index+1]}"
- )
- encrypted_tekst += alphabet[value]
- index += 2
- return encrypted_tekst
- matrix_text = create_matrix(tekst_jawny)
- print(matrix_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement