-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpublickeysystem_test.py
43 lines (30 loc) · 2 KB
/
publickeysystem_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest
from publickeysystem import encrypt_pipeline, decrypt_pipeline, compute_d, phi
@pytest.fixture
def test_set():
m = "Factoring lets us break RSA."
c = "22096451867410381776306561134883418017410069787892831071731839143676135600120538004282329650473509424343946219751512256465839967942889460764542040581564748988013734864120452325229320176487916666402997509188729971690526083222067771600019329260870009579993724077458967773697817571267229951148662959627934791540"
e = '65537'
N = "179769313486231590772930519078902473361797697894230657273430081157732675805505620686985379449212982959585501387537164015710139858647833778606925583497541085196591615128057575940752635007475935288710823649949940771895617054361149474865046711015101563940680527540071584560878577663743040086340742855278549092581"
p = "13407807929942597099574024998205846127479365820592393377723561443721764030073662768891111614362326998675040546094339320838419523375986027530441562135724301"
q = "13407807929942597099574024998205846127479365820592393377723561443721764030073778560980348930557750569660049234002192590823085163940025485114449475265364281"
d = "15901287978999413029444103622387317669077639420371013629157181141513592652158568184727012903658813528491037910547521854815931164999641308185976587386289355866678615944319681939473842195092207377098269996346353744109549011306581302639353136684586796229221071755410527734011645528084075140176976118813890397473"
return m, c, e, d, N, p, q
def test1(test_set):
_, _, e, d, N, p, q = test_set
d_phiN = compute_d(e, N, p, q)
assert d == d_phiN
def test2(test_set):
pt, ct1, e, d, N, p, q = test_set
m1 = decrypt_pipeline(ct1, d, N)
assert m1 == pt
def test3(test_set):
pt, ct1, e, d, N, p, q = test_set
ct2 = encrypt_pipeline(pt, e, N)
ct3 = encrypt_pipeline(pt, e, N)
m1 = decrypt_pipeline(ct1, d, N)
m2 = decrypt_pipeline(ct2, d, N)
m3 = decrypt_pipeline(ct3, d, N)
assert m1 == pt
assert m2 == pt
assert m3 == pt