feat: Вынес тесты в отдельный файл
This commit is contained in:
parent
c054da67f1
commit
893bf71528
2 changed files with 50 additions and 53 deletions
50
McEliece_tests.py
Normal file
50
McEliece_tests.py
Normal file
|
@ -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()
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue