Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/test/test_acd.py
2587 views
1
import os
2
import sys
3
from unittest import TestCase
4
5
path = os.path.dirname(os.path.dirname(os.path.realpath(os.path.abspath(__file__))))
6
if sys.path[1] != path:
7
sys.path.insert(1, path)
8
9
from attacks.acd import mp
10
from attacks.acd import ol
11
from attacks.acd import sda
12
13
14
class TestACD(TestCase):
15
def test_mp(self):
16
p = 13845249886873428613
17
N = 217407154917807470895390029782610665191
18
a = [217533070209246692596654921907507416418, 204580044578352963965866243184761160753, 140701572771317740546493579818249256489, 204965623030303278851699918560590728481]
19
r = [-4487, -10300, -10075, 23477]
20
rho = 16
21
p_, r_ = mp.attack(N, a, rho)
22
self.assertIsInstance(p_, int)
23
self.assertEqual(p, p_)
24
for i in range(len(r)):
25
self.assertIsInstance(r_[i], int)
26
self.assertEqual(r[i], r_[i])
27
28
p = 4238219929
29
N = 169749234656568819546953289884491257755
30
a = [244914656571365600647675250712402894810, 258938327120706515107425576685234055392, 304762109988168193461144822345045328384, 331420653433993738593271242794196239800, 213192828695455264854663438180715919066, 178555459224222734102095815362417919512, 240756376346047770614611034188210416410, 168622111253832154566397598758889653217]
31
r = [48611, 26045, -62765, -18028, -9003, -23809, -42845, -45828]
32
rho = 16
33
p_, r_ = mp.attack(N, a, rho)
34
self.assertIsInstance(p_, int)
35
self.assertEqual(p, p_)
36
for i in range(len(r)):
37
self.assertIsInstance(r_[i], int)
38
self.assertEqual(r[i], r_[i])
39
40
def test_ol(self):
41
p = 13845249886873428613
42
x = [217533070209246692596654921907507416418, 204580044578352963965866243184761160753, 140701572771317740546493579818249256489, 204965623030303278851699918560590728481]
43
r = [-4487, -10300, -10075, 23477]
44
rho = 16
45
p_, r_ = ol.attack(x, rho)
46
self.assertIsInstance(p_, int)
47
self.assertEqual(p, p_)
48
for i in range(len(r)):
49
self.assertIsInstance(r_[i], int)
50
self.assertEqual(r[i], r_[i])
51
52
p = 4238219929
53
x = [244914656571365600647675250712402894810, 258938327120706515107425576685234055392, 304762109988168193461144822345045328384, 331420653433993738593271242794196239800, 213192828695455264854663438180715919066, 178555459224222734102095815362417919512, 240756376346047770614611034188210416410, 168622111253832154566397598758889653217]
54
r = [48611, 26045, -62765, -18028, -9003, -23809, -42845, -45828]
55
rho = 16
56
p_, r_ = ol.attack(x, rho)
57
self.assertIsInstance(p_, int)
58
self.assertEqual(p, p_)
59
for i in range(len(r)):
60
self.assertIsInstance(r_[i], int)
61
self.assertEqual(r[i], r_[i])
62
63
def test_sda(self):
64
p = 13845249886873428613
65
x = [217533070209246692596654921907507416418, 204580044578352963965866243184761160753, 140701572771317740546493579818249256489, 204965623030303278851699918560590728481]
66
r = [-4487, -10300, -10075, 23477]
67
rho = 16
68
p_, r_ = sda.attack(x, rho)
69
self.assertIsInstance(p_, int)
70
self.assertEqual(p, p_)
71
for i in range(len(r)):
72
self.assertIsInstance(r_[i], int)
73
self.assertEqual(r[i], r_[i])
74
75
p = 4238219929
76
x = [244914656571365600647675250712402894810, 258938327120706515107425576685234055392, 304762109988168193461144822345045328384, 331420653433993738593271242794196239800, 213192828695455264854663438180715919066, 178555459224222734102095815362417919512, 240756376346047770614611034188210416410, 168622111253832154566397598758889653217]
77
r = [48611, 26045, -62765, -18028, -9003, -23809, -42845, -45828]
78
rho = 16
79
p_, r_ = sda.attack(x, rho)
80
self.assertIsInstance(p_, int)
81
self.assertEqual(p, p_)
82
for i in range(len(r)):
83
self.assertIsInstance(r_[i], int)
84
self.assertEqual(r[i], r_[i])
85
86