Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 8796
1
r"""
2
Check the cast128 database.
3
"""
4
5
#*****************************************************************************
6
# Copyright (C) 2017 Paul Leopardi [email protected]
7
#
8
# Distributed under the terms of the GNU General Public License (GPL)
9
# as published by the Free Software Foundation; either version 2 of
10
# the License, or (at your option) any later version.
11
# http://www.gnu.org/licenses/
12
#*****************************************************************************
13
14
import datetime
15
import json
16
import psycopg2
17
18
from boolean_cayley_graphs.bent_function import BentFunction
19
from boolean_cayley_graphs.bent_function_cayley_graph_classification import BentFunctionCayleyGraphClassification
20
from boolean_cayley_graphs.classification_database_psycopg2 import *
21
22
print("Checking the Cayley graph classifications of bent functions from the CAST-128 S-boxes.")
23
24
with open("postgresql-auth.json") as auth_file:
25
auth = json.load(auth_file)
26
27
conn = connect_to_database(
28
"cast128",
29
user=auth["user"],
30
password=auth["password"],
31
host=auth["host"])
32
33
curs = conn.cursor()
34
print(datetime.datetime.now(), "before")
35
curs.execute("SELECT COUNT(*) FROM cayley_graph")
36
print(datetime.datetime.now(), "after")
37
print("Number of Cayley graphs of bent functions:")
38
for row in curs:
39
for x in row:
40
print(x)
41
42
print(datetime.datetime.now(), "before")
43
curs.execute("SELECT COUNT(*) FROM graph")
44
print(datetime.datetime.now(), "after")
45
print("Number of non-isomorphic graphs:")
46
for row in curs:
47
for x in row:
48
print(x)
49
50
print("Checking cast128_8_31 by name in database:")
51
cgc1 = select_classification_where_name(
52
conn,
53
"cast128_8_31")
54
cgc1.report()
55
56
cgc2 = BentFunctionCayleyGraphClassification.load_mangled(
57
"cast128_8_31",
58
directory="/data/sobj")
59
bentf = BentFunction(cgc2.algebraic_normal_form)
60
61
print("Checking cast128_8_31 by bent function in database:")
62
cgc3 = select_classification_where_bent_function(
63
conn,
64
bentf)
65
cgc3.report()
66
67
print("")
68
print("Checking for graphs occuring as the Cayley graph of more than 1 bent function.")
69
curs = conn.cursor()
70
print(datetime.datetime.now(), "before")
71
curs.execute("""
72
select name, cayley_graph_index, graph_id, count(*)
73
from matrices, (
74
select name, bent_function, cayley_graph_index, graph_id
75
from (
76
select graph_id
77
from cayley_graph
78
group by graph_id
79
having count (graph_id) > 1 ) as repeats
80
natural join cayley_graph
81
natural join bent_function )
82
as repeats_with_counts
83
where matrices.bent_function = repeats_with_counts.bent_function
84
and matrices.bent_cayley_graph_index = repeats_with_counts.cayley_graph_index
85
group by name, cayley_graph_index, graph_id
86
order by graph_id
87
""")
88
print(datetime.datetime.now(), "after")
89
print("Repeated graphs:")
90
for row in curs:
91
for x in row:
92
print(x, end=' ')
93
print("")
94
95
conn.close()
96
97
98