2020-02-18 01:41:29 -08:00
|
|
|
#!/usr/bin/python3
|
2019-10-25 15:23:02 -07:00
|
|
|
|
2020-02-18 01:42:41 -08:00
|
|
|
# This checks the cases k = 1 and k = 2 needed to complete the proof of the
|
|
|
|
# injectivity lemma in Appendix C of <https://eprint.iacr.org/2019/1021>.
|
|
|
|
|
2019-10-25 15:23:02 -07:00
|
|
|
from itertools import product
|
2020-02-18 01:41:29 -08:00
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
cd_pair = namedtuple('cd_pair', ['c', 'd'])
|
2019-10-25 15:23:02 -07:00
|
|
|
|
2020-02-18 01:33:36 -08:00
|
|
|
def c_d():
|
2020-02-18 01:41:29 -08:00
|
|
|
yield cd_pair(-1, 0)
|
|
|
|
yield cd_pair( 1, 0)
|
|
|
|
yield cd_pair( 0, -1)
|
|
|
|
yield cd_pair( 0, 1)
|
2019-10-25 15:23:02 -07:00
|
|
|
|
2020-02-18 01:33:36 -08:00
|
|
|
def sums_mod4(cd):
|
2020-02-18 01:41:29 -08:00
|
|
|
return ((2**(k+1) + sum([cd[j].c * (2**j) for j in range(k)])) % 4,
|
|
|
|
(2**(k+1) + sum([cd[j].d * (2**j) for j in range(k)])) % 4)
|
2019-10-25 15:23:02 -07:00
|
|
|
|
|
|
|
for k in (1, 2):
|
2020-02-18 01:33:36 -08:00
|
|
|
M_k = [list(s) for s in product(c_d(), repeat=k)]
|
2019-10-25 15:23:02 -07:00
|
|
|
assert(len(M_k) == 4**k)
|
|
|
|
|
2020-11-19 11:52:22 -08:00
|
|
|
for cd in M_k:
|
|
|
|
print("%r -> %r" % (cd, sums_mod4(cd)))
|
|
|
|
|
2020-02-18 01:33:36 -08:00
|
|
|
for (cd, cd_dash) in product(M_k, repeat=2):
|
|
|
|
if cd[0] != cd_dash[0]:
|
|
|
|
assert(sums_mod4(cd) != sums_mod4(cd_dash))
|
2019-10-25 15:23:02 -07:00
|
|
|
|
|
|
|
print("QED")
|