kolos z algo xdd

This commit is contained in:
2025-12-02 16:56:35 +01:00
parent eb76bc51e8
commit 6d1a1eae03
17 changed files with 414 additions and 311 deletions

View File

@@ -0,0 +1,50 @@
import numpy as np
def letter_to_num(letter):
return ord(letter.upper()) - ord('A')
def num_to_letter(num):
return chr(num + ord('A'))
def cipher(text: str):
k = np.array([[3, 3], [2, 5]])
text_upper = text.upper().replace(' ', '')
if len(text_upper) % 2 != 0:
text_upper += "X"
text_number = [letter_to_num(letter) for letter in text_upper]
text_matrix = np.array(text_number).reshape(-1, 2).T
c = (k @ text_matrix) % 26
cipher_text = ''.join(num_to_letter(num) for num in c.T.flatten())
return cipher_text
def decipher(text: str):
k = np.array([[3, 3], [2, 5]])
k_inv = np.linalg.inv(k)
text_upper = text.upper().replace(' ', '')
if len(text_upper) % 2 != 0:
text_upper += "X"
text_number = [letter_to_num(letter) for letter in text_upper]
text_matrix = np.array(text_number).reshape(-1, 2).T
c = (k_inv @ text_matrix) % 26
cipher_text = ''.join(num_to_letter(num) for num in c.T.flatten())
return cipher_text
if __name__ == "__main__":
test_text = "Test"
cipher = cipher(test_text)
#decipher = decipher(cipher)
print("Text: ", test_text)
print("cipher: ", cipher)

View File

@@ -0,0 +1,3 @@
- 19*69* powstała pierwsze sieć komputerowa. 69 buahahha
- amazon pierwsza księgarnia internetowa
- frontend bakend