Skip to content

Commit

Permalink
Update cryptix.py
Browse files Browse the repository at this point in the history
  • Loading branch information
president-xd authored Aug 20, 2024
1 parent 8432d95 commit 8b8e905
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Cryptix/cryptix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import base64
from typing import List


EXCEPTION_MESSAGE = "Exception occurred: "

# Extended Morse code dictionary with some special characters
Expand All @@ -19,12 +18,12 @@
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..', '0': '-----', '1': '.----', '2': '..---',
'3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...',
'8': '---..', '9': '----.', ' ': '/',
'.': '.-.-.-', ',': '--..--', '?': '..--..', '\'': '.----.',
'!': '-.-.--', '/': '-..-.', '(': '-.--.', ')': '-.--.-',
'&': '.-...', ':': '---...', ';': '-.-.-.', '=': '-...-',
'+': '.-.-.', '-': '-....-', '_': '..--.-', '"': '.-..-.',
'@': '.--.-.',
'8': '---..', '9': '----.', ' ': '/',
'.': '.-.-.-', ',': '--..--', '?': '..--..', '\'': '.----.',
'!': '-.-.--', '/': '-..-.', '(': '-.--.', ')': '-.--.-',
'&': '.-...', ':': '---...', ';': '-.-.-.', '=': '-...-',
'+': '.-.-.', '-': '-....-', '_': '..--.-', '"': '.-..-.',
'@': '.--.-.',
'{': '-.-..-', '}': '-.-.-.', '[': '-.--.', ']': '-.--.-',
'<': '..-.-', '>': '---.-.'
}
Expand Down Expand Up @@ -67,13 +66,14 @@ def brute_force_decode(cipher, known_text):

if decodeee[: len(known_text)] == known_text:
return found_key

break
else:
print(f"No key found for digit: {digit}")
break

return found_key

@staticmethod
def mod_inverse(a, m):
"""Find the modular inverse of a under modulus m."""
Expand All @@ -89,13 +89,10 @@ def decrypt_hill_cipher(ciphertext, key_matrix):
try:
key_matrix = np.array(key_matrix)
determinant = int(np.round(np.linalg.det(key_matrix)))

# Compute modular inverse of determinant
determinant_inv = Cryptix.mod_inverse(determinant, 26)

# Calculate the inverse matrix
key_matrix_inv = determinant_inv * np.round(determinant * np.linalg.inv(key_matrix)).astype(int) % 26

ciphertext_vectors = [ord(char.upper()) - ord('A') for char in ciphertext if char.isalpha()]
plaintext_vectors = []

Expand Down Expand Up @@ -687,5 +684,4 @@ def decode_morse_code_encoding(morse_code):
reverse_dict = {value: key for key, value in MORSE_CODE_DICT.items()}
morse_code = morse_code.strip().split(' ')
decoded_text = ''.join(reverse_dict.get(code, '') for code in morse_code)
return decoded_text

return decoded_text

0 comments on commit 8b8e905

Please sign in to comment.