fix: Подкорректировал работу с исключениями

nihonium
Nihonium 1 month ago
parent 893bf71528
commit d66419d906
Signed by: nihonium
GPG Key ID: 0251623741027CFC

@ -1,5 +1,3 @@
#pyinstaller -F -i "icon.ico" McEliece_console_v2.py
import hashlib
import getpass
@ -9,8 +7,8 @@ def main():
def safe_start():
try:
start_menu()
except:
print("\nUnknown error (maybe ctrl+c), emergency exit!")
except (KeyboardInterrupt, EOFError):
print("\nExiting...")
def start_menu():
f = True
@ -29,7 +27,7 @@ def start_menu():
input()
def menu():
import cryptosystem_core_v2 as ME_core
import cryptosystem_core as ME_core
core = ME_core.McEliece_core()
global_info = "All files are interpreted as raw bytes and must be located in the directory with this executable file.\nDefault filenames with .bin extension: pubkey, privkey_S, privkey_p, plaintext, ciphertext, ciphered_string.\nDon't forget to import (or generate) keys before encryption/decryption and after changing config!\nYou can restore any one key from two another (don't forget to import before).\n"
info = "Menu numbers: 0 = exit, s = print short info, h = print this info, g = print global info, c = change config;\n1 = generate keys, 10 = unsafe generate keys (seed = hash(password)),\n11 = export pubkey, 12 = export privkey_S, 13 = export privkey_p,\n14 = import pubkey, 15 = import privkey_S, 16 = import privkey_p,\n17 = restore pubkey, 18 = restore privkey_S, 19 = restore privkey_p;\n2 = encrypt,\n21 = encrypt non-default filename, 22 = encrypt string from keyboard, 23 = encrypt hided string.\n3 = decrypt,\n31 = decrypt non-default filename, 32 = decrypt string and show on screen\n"

@ -30,7 +30,7 @@ class McEliece_core:
raise Exception()
rs = galois.ReedSolomon(n, k, field = self._GF)
except:
raise Exception()
raise
else:
self._n = n
self._k = k
@ -65,7 +65,7 @@ class McEliece_core:
G = [G[i - self._n : i] for i in range(self._n, self._n * self._k + self._n, self._n)]
G = self._GF(G)
except:
raise Exception()
raise
else:
self._G = G
def set_privkey_S(self, S):
@ -74,7 +74,7 @@ class McEliece_core:
S = self._GF(S)
S_inv = np.linalg.inv(S)
except:
raise Exception()
raise
else:
self._S = S
self._S_inv = S_inv
@ -96,7 +96,7 @@ class McEliece_core:
try:
S_inv = np.linalg.inv(S)
except:
raise Exception()
raise
self._S = S
self._S_inv = S_inv
def restore_privkey_p(self):
@ -134,14 +134,14 @@ class McEliece_core:
out += self._encrypt_one(text)
return out
except:
raise Exception()
raise
def decrypt(self, msg):
try:
msg = [msg[i - self._n : i] for i in range(self._n, len(msg) + self._n, self._n)]
msg = [self._decrypt_one(self._GF(i)) for i in msg]
return [i for j in msg for i in j]
except:
raise Exception()
raise
#End of top-level functions, please do NOT use functions below without understanding!
def _generate_S(self):
S = self._GF.Random((self._k, self._k))
@ -199,7 +199,7 @@ class McEliece_core:
try:
msg = self._unpad_message(msg)
except:
raise Exception()
raise
return msg
def _pad_message(self, msg):
last_value = self._k - (len(msg) % self._k)

Loading…
Cancel
Save