-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
94 lines (81 loc) · 1.72 KB
/
config.py
File metadata and controls
94 lines (81 loc) · 1.72 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Helper functions and classes to configure the execution.
"""
import logging
from dataclasses import dataclass
from types import ModuleType
from typing import Any
logger = logging.getLogger(__name__)
# ---------------------- FUNCTIONS -------------------------
def set_constant(module :ModuleType, name :str, value :Any) -> None:
"""
Set the given constant of the given module to the given value.
Parameters
----------
``module``: ModuleType
The module to set the constant on.
``name``: str
The name of the constant to set.
``value``: Any
The value to set the constant to.
"""
if not hasattr(module, name):
logger.warning(f"{module} has no constant '{name}'")
setattr(module, name, value)
return
# ---------------------- CLASSES ---------------------------
@dataclass
class CipherParams():
"""
Dataclass containing parameters related to the chosen cipher.
"""
name :str
"""
Cipher name.
"""
encrypt_func :callable
"""
Function to encrypt data.
"""
key_size :int
"""
Key size in number of words.
"""
plain_size :int
"""
Plaintext size in number of words.
"""
word_size :int
"""
Number of bits per word.
"""
word_type :type
"""
Numpy or Cupy type of the words.
"""
@dataclass
class EvoalgParams():
"""
Dataclass containing parameters related to the chosen evolutionary algo.
"""
name :str
"""
Name of the algorithm.
"""
evolve_func :callable
"""
Function to call the algorithm.
"""
@dataclass
class FitnessParams():
"""
Dataclass containing parameters related to the chosen fitness function.
"""
name :str
"""
Name of the function.
"""
evaluate_func :callable
"""
Function to call to evaluate the differences.
"""