diff --git a/McEliece_tests.py b/McEliece_tests.py new file mode 100644 index 0000000..83028c1 --- /dev/null +++ b/McEliece_tests.py @@ -0,0 +1,50 @@ +from cryptosystem_core import * + +def main(): #comment "return" for testing + core = McEliece_core() + n, k = core.get_config() + print(n, k) + core.change_config(5, 3) #check comments in class implementation to understand possible values + n, k = core.get_config() + print(n, k) + print() + core.generate_keys() #true random + print(core.get_pubkey()) + print(core.get_privkey_S()) + print(core.get_privkey_p()) + print() + core.generate_keys(sum([ord(i) for i in list("password")])) #very simple seed + G = core.get_pubkey() + S = core.get_privkey_S() + p = core.get_privkey_p() + print(G) + print(S) + print(p) + print() + core.change_config(5, 3) #unset all keys inside core + core.set_privkey_S(S) + core.set_privkey_p(p) + core.restore_pubkey() + print(core.get_pubkey() == G) + core.change_config(5, 3) #unset all keys inside core + core.set_pubkey(G) + core.set_privkey_p(p) + core.restore_privkey_S() + print(core.get_privkey_S() == S) + core.change_config(5, 3) #unset all keys inside core + core.set_pubkey(G) + core.set_privkey_S(S) + core.restore_privkey_p() + print(core.get_privkey_p() == p) + print() + for j in range(2): + text = [i + 1 for i in range(5)] + msg = core.encrypt(text) + print(msg) + text = core.decrypt(msg) + print(text) + print() + print("All tests are finished!") + +if __name__ == "__main__": + main() diff --git a/cryptosystem_core.py b/cryptosystem_core.py index eaf3070..66fd2f7 100644 --- a/cryptosystem_core.py +++ b/cryptosystem_core.py @@ -11,56 +11,6 @@ import numpy as np import galois import random -#import cryptosystem_core_v2 as ME_core -#core = ME_core.McEliece_core() - -def main(): #comment "return" for testing - return - core = McEliece_core() - n, k = core.get_config() - print(n, k) - core.change_config(5, 3) #check comments in class implementation to understand possible values - n, k = core.get_config() - print(n, k) - print() - core.generate_keys() #true random - print(core.get_pubkey()) - print(core.get_privkey_S()) - print(core.get_privkey_p()) - print() - core.generate_keys(sum([ord(i) for i in list("password")])) #very simple seed - G = core.get_pubkey() - S = core.get_privkey_S() - p = core.get_privkey_p() - print(G) - print(S) - print(p) - print() - core.change_config(5, 3) #unset all keys inside core - core.set_privkey_S(S) - core.set_privkey_p(p) - core.restore_pubkey() - print(core.get_pubkey() == G) - core.change_config(5, 3) #unset all keys inside core - core.set_pubkey(G) - core.set_privkey_p(p) - core.restore_privkey_S() - print(core.get_privkey_S() == S) - core.change_config(5, 3) #unset all keys inside core - core.set_pubkey(G) - core.set_privkey_S(S) - core.restore_privkey_p() - print(core.get_privkey_p() == p) - print() - for j in range(2): - text = [i + 1 for i in range(5)] - msg = core.encrypt(text) - print(msg) - text = core.decrypt(msg) - print(text) - print() - print("All tests are finished!") - class McEliece_core: def __init__(self): self._order = 256 #p^m = 2**8; encryption of each byte @@ -262,6 +212,3 @@ class McEliece_core: if msg[-i] != last_value: raise Exception() return msg[: -last_value] - -if __name__ == "__main__": - main()