isoring 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
isoring-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Richard Pham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
isoring-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: isoring
3
+ Version: 0.0.1
4
+ Summary: A structure for data security and a cracking environment.
5
+ Home-page: https://github.com/Changissnz/isoring
6
+ Author: Richard Pham
7
+ Author-email: Richard Pham <phamrichard45@gmail.com>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/changissnz/isoring
10
+ Project-URL: Issues, https://github.com/changissnz/isoring/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: author
17
+ Dynamic: home-page
18
+ Dynamic: license-file
19
+
20
+ # isoring
21
+ a component from the terminated project, puissec.
22
+
23
+ A structure called the `IsoRingedChain` is supposed to guard a big secret, comprised of a sequence
24
+ of arbitrarily-lengthed vectors (secrets).
25
+
26
+ # What is a Secret?
27
+
28
+ Who knows, really?
29
+
30
+ In this computer program, a secret is represented by a finitely lengthed vector. The `Sec` structure contains this vector of
31
+ length `n`, as well as `k` additional vectors in the same dimension of `n`. These `k+1` vectors are the local optima of
32
+ `n`-space in real numbers. Every one of those vectors has an associated probability value, the probability values adding up
33
+ to one. These probability values can be arbitrary, meaning the actual secret (vector) of `Sec` may have any probability
34
+ value in `[0,1.]`. Design of `Sec` is based on the common machine-learning problem of choosing local optima over the best
35
+ solution.
36
+
37
+ The `IsoRing` structure contains the secret, a vector in finite space. It contains that secret in one `Sec` instance.
38
+ `IsoRing` also holds an additional `j` `Sec` instances, each of these `Sec` instances in a unique finite vector
39
+ dimension. These `j` instances serve as buffers to third-party acquisition of the actual `Sec` instance. In effect,
40
+ `IsoRing` has two primary layers of defenses: the `j` `Sec` instances and the `r_j >= 1` alternative local optima to
41
+ the actual vector of some `Sec`.
42
+
43
+ At any point in program run, outward representative of `IsoRing` is exactly one `Sec` instance, the isomorphic
44
+ representation (iso-repr).
45
+
46
+ In order for a third-party to interact with an `IsoRing` for information, third-party will have to interact with
47
+ feedback function of `IsoRing`. For an `IsoRing` in iso-repr vector dimension `q`, feedback function provides a
48
+ `q`-vector of distance scores. Distance scores are conventionally euclidean point distances. However, there are
49
+ alternative feedback functions that provide distorted distance scores via pseudo-random number generator.
50
+
51
+ For a sequence of arbitrarily-lengthed vectors (secrets), an `IsoRingedChain` is used to cover it and this structure
52
+ is, in turn, composed of a number of `IsoRing`s equal to the number of those vectors (secrets).
53
+
54
+ # What is an Isomorphic Ringed Chain?
55
+
56
+ An `IsoRingedChain` guards a sequence of vectors (secrets). Any of the `IsoRing`s in an `IsoRingedChain` may be in
57
+ an isomorphic representation not of the same dimension of the actual secret. Additionally, every `IsoRing` in an
58
+ `IsoRingedChain` has dependencies and co-dependencies in order for third-party access to it. Dependencies are the
59
+ `IsoRing`s that must have been "cracked" by the third-party before getting to it, and co-dependencies are the
60
+ `IsoRing`s that must be "cracked" alongside it. Cracking cannot proceed by an ordering of the `IsoRing`s that
61
+ violate the specified dependencies and co-dependencies linking these structures together for the `IsoRingedChain`.
62
+
63
+ # What is Cracking?
64
+
65
+ In this program, the `Cracker` structure is responsible for determining all the secrets of an `IsoRingedChain`. This
66
+ process of determination is "cracking". The `Cracker` must attempt cracking in the order specified by all of the
67
+ contained `IsoRing`s' dependencies and co-dependencies. Otherwise, program will halt `Cracker` midway, resulting in
68
+ its failure.
69
+
70
+ `Cracker` is given background information, `BackgroundInfo`, on the target `IsoRingedChain`.
71
+
72
+ NOTE: There are deficits to this map design of background information. However, it was chosen because it avoids the
73
+ Curse of Dimensionality, one of a few major problems that plagued successful complete development of the
74
+ program `puissec`, found at `github.com/changissnz/puissec`. Program `puissec` was the predecessor of this
75
+ program `isoring`. Program `isoring` is, in fact, a simpler version of only part of the problems in the
76
+ conceptualization of `puissec`.
77
+
78
+ `BackgroundInfo` has three main components.
79
+ 1. Hypothesis map,
80
+ `<Isoring> identifier -> <Sec> index -> <HypStruct>`.
81
+ 2. Suspected `IsoRing`-to-`Sec` map,
82
+ `<Isoring> identifier -> <Sec> index`.
83
+ 3. Order of cracking, a sequence with each element
84
+ `{set of co-dependent IsoRing identifiers}`.
85
+
86
+ One deficit about design of this `BackgroundInfo` is the hypothesis map. Every `Sec` instance can have at
87
+ most one hypothesis on it. And the `HypStruct` is focused on exactly one local optimum.
88
+
89
+ `HypStruct` represents a hypothesis on a `Sec`, of vector dimension `k`, and has these attributes.
90
+ 1. Suspected optima index `i` of the `Sec`.
91
+ 2. Bounds (a `k x 2` matrix) suspected to contain optima `i`.
92
+ 3. Hop size `h`, an integer, uniformly partitioning the bounds into `k x h` points.
93
+ 4. Probability marker `P`, used to cross-reference with probability output value `P'` from a
94
+ cracked `Sec`.
95
+
96
+ The probability values in this program are meant to be reference values for a `Cracker`. If a `Cracker`
97
+ uses a `HypStruct` to crack `Sec`, and the output probability from `Sec` differs from that of the
98
+ `HypStruct` used, then the `Cracker` does not accept the cracking vector as the actual secret.
99
+
100
+ NOTE: these are information games, broadly speaking.
101
+
102
+ For every `IsoRing` being targeted by a `Cracker`, `Cracker` uses one `Crackling` at any one time, in
103
+ order to attempt to crack the `IsoRing` for the vector (secret) of the `IsoRing`'s suspected `Sec`. A
104
+ `Cracker` will attempt to use as many `Crackling`s, in re-cracking sessions, for an `IsoRing` as program
105
+ permits until `Cracker` cracks its wanted local optimum from the suspected `Sec` of said `IsoRing`.
106
+
107
+ A structure called a `SearchSpaceIterator` is employed by every `Crackling` to execute brute-force
108
+ cracking attempts on an `IsoRing`'s isomorphic representation. `SearchSpaceIterator` outputs `k x h`
109
+ points that uniformly cover the input bounds of matrix `k x 2`.
110
+
111
+ If the `Cracker` does not a `HypStruct` for the `IsoRing`'s isomorphic representation (the second
112
+ layer in the three-layer hypothesis map), program halts `Cracker` midway. If the `Crackling` is
113
+ successful in cracking the isomorphic representation, `IsoRing` has to switch its isomorphic representation
114
+ to an uncracked `Sec`. If there are none that have not been cracked, `IsoRing` stops switching its
115
+ isomorphic representation due to the `Cracker` no longer being interested in cracking it anymore.
116
+
117
+ If a `Crackling` does not produce any (vector, associated probability value) on a `Sec`, `Cracker` cannot
118
+ proceed to attempting to crack any `IsoRing`s dependent on the `IsoRing`, pertaining to said `Sec`, being
119
+ cracked. In most cases, `Cracker` would be halted.
120
+
121
+ # The Brute-Force Environment
122
+
123
+ There Are Rules To The Game. The rules are enforced in the environment `BruteForceEnv`, where a `Cracker`
124
+ attempts to crack an `IsoRingedChain`. A `Cracker` is granted some arbitrary amount of energy, a real number.
125
+ If the energy falls to zero or below, program halts `Cracker`. A `Cracker` can use only `t` number of
126
+ `Crackling`s at once. If there are co-dependent `IsoRing` sets in `IsoRingedChain` that are greater in size
127
+ than `t`, successfully cracking the `IsoRingedChain` is impossible for the `Cracker`.
128
+
129
+ # What is Successful Cracking? Complete Execution or Complete Acquisition of Actual?
130
+
131
+ The complete execution of cracking all the `IsoRing`s in an `IsoRingedChain` can be known by a `Cracker` by
132
+ the time the program halts `Cracker`. However, the `BackgroundInfo` of a `Cracker` is what allows it to verify
133
+ on what the actual vectors from `IsoRingedChain` are.
134
+
135
+ # Additional Features
136
+
137
+ Generative methods, found in this program, can be used to produce the relevant data structures. These
138
+ methods do come in handy since there are a lot of variables to type up by hand.
139
+
140
+ # An Example On the User Interface
141
+
142
+ ![Screenshot](screeshantaya.png)
@@ -0,0 +1,123 @@
1
+ # isoring
2
+ a component from the terminated project, puissec.
3
+
4
+ A structure called the `IsoRingedChain` is supposed to guard a big secret, comprised of a sequence
5
+ of arbitrarily-lengthed vectors (secrets).
6
+
7
+ # What is a Secret?
8
+
9
+ Who knows, really?
10
+
11
+ In this computer program, a secret is represented by a finitely lengthed vector. The `Sec` structure contains this vector of
12
+ length `n`, as well as `k` additional vectors in the same dimension of `n`. These `k+1` vectors are the local optima of
13
+ `n`-space in real numbers. Every one of those vectors has an associated probability value, the probability values adding up
14
+ to one. These probability values can be arbitrary, meaning the actual secret (vector) of `Sec` may have any probability
15
+ value in `[0,1.]`. Design of `Sec` is based on the common machine-learning problem of choosing local optima over the best
16
+ solution.
17
+
18
+ The `IsoRing` structure contains the secret, a vector in finite space. It contains that secret in one `Sec` instance.
19
+ `IsoRing` also holds an additional `j` `Sec` instances, each of these `Sec` instances in a unique finite vector
20
+ dimension. These `j` instances serve as buffers to third-party acquisition of the actual `Sec` instance. In effect,
21
+ `IsoRing` has two primary layers of defenses: the `j` `Sec` instances and the `r_j >= 1` alternative local optima to
22
+ the actual vector of some `Sec`.
23
+
24
+ At any point in program run, outward representative of `IsoRing` is exactly one `Sec` instance, the isomorphic
25
+ representation (iso-repr).
26
+
27
+ In order for a third-party to interact with an `IsoRing` for information, third-party will have to interact with
28
+ feedback function of `IsoRing`. For an `IsoRing` in iso-repr vector dimension `q`, feedback function provides a
29
+ `q`-vector of distance scores. Distance scores are conventionally euclidean point distances. However, there are
30
+ alternative feedback functions that provide distorted distance scores via pseudo-random number generator.
31
+
32
+ For a sequence of arbitrarily-lengthed vectors (secrets), an `IsoRingedChain` is used to cover it and this structure
33
+ is, in turn, composed of a number of `IsoRing`s equal to the number of those vectors (secrets).
34
+
35
+ # What is an Isomorphic Ringed Chain?
36
+
37
+ An `IsoRingedChain` guards a sequence of vectors (secrets). Any of the `IsoRing`s in an `IsoRingedChain` may be in
38
+ an isomorphic representation not of the same dimension of the actual secret. Additionally, every `IsoRing` in an
39
+ `IsoRingedChain` has dependencies and co-dependencies in order for third-party access to it. Dependencies are the
40
+ `IsoRing`s that must have been "cracked" by the third-party before getting to it, and co-dependencies are the
41
+ `IsoRing`s that must be "cracked" alongside it. Cracking cannot proceed by an ordering of the `IsoRing`s that
42
+ violate the specified dependencies and co-dependencies linking these structures together for the `IsoRingedChain`.
43
+
44
+ # What is Cracking?
45
+
46
+ In this program, the `Cracker` structure is responsible for determining all the secrets of an `IsoRingedChain`. This
47
+ process of determination is "cracking". The `Cracker` must attempt cracking in the order specified by all of the
48
+ contained `IsoRing`s' dependencies and co-dependencies. Otherwise, program will halt `Cracker` midway, resulting in
49
+ its failure.
50
+
51
+ `Cracker` is given background information, `BackgroundInfo`, on the target `IsoRingedChain`.
52
+
53
+ NOTE: There are deficits to this map design of background information. However, it was chosen because it avoids the
54
+ Curse of Dimensionality, one of a few major problems that plagued successful complete development of the
55
+ program `puissec`, found at `github.com/changissnz/puissec`. Program `puissec` was the predecessor of this
56
+ program `isoring`. Program `isoring` is, in fact, a simpler version of only part of the problems in the
57
+ conceptualization of `puissec`.
58
+
59
+ `BackgroundInfo` has three main components.
60
+ 1. Hypothesis map,
61
+ `<Isoring> identifier -> <Sec> index -> <HypStruct>`.
62
+ 2. Suspected `IsoRing`-to-`Sec` map,
63
+ `<Isoring> identifier -> <Sec> index`.
64
+ 3. Order of cracking, a sequence with each element
65
+ `{set of co-dependent IsoRing identifiers}`.
66
+
67
+ One deficit about design of this `BackgroundInfo` is the hypothesis map. Every `Sec` instance can have at
68
+ most one hypothesis on it. And the `HypStruct` is focused on exactly one local optimum.
69
+
70
+ `HypStruct` represents a hypothesis on a `Sec`, of vector dimension `k`, and has these attributes.
71
+ 1. Suspected optima index `i` of the `Sec`.
72
+ 2. Bounds (a `k x 2` matrix) suspected to contain optima `i`.
73
+ 3. Hop size `h`, an integer, uniformly partitioning the bounds into `k x h` points.
74
+ 4. Probability marker `P`, used to cross-reference with probability output value `P'` from a
75
+ cracked `Sec`.
76
+
77
+ The probability values in this program are meant to be reference values for a `Cracker`. If a `Cracker`
78
+ uses a `HypStruct` to crack `Sec`, and the output probability from `Sec` differs from that of the
79
+ `HypStruct` used, then the `Cracker` does not accept the cracking vector as the actual secret.
80
+
81
+ NOTE: these are information games, broadly speaking.
82
+
83
+ For every `IsoRing` being targeted by a `Cracker`, `Cracker` uses one `Crackling` at any one time, in
84
+ order to attempt to crack the `IsoRing` for the vector (secret) of the `IsoRing`'s suspected `Sec`. A
85
+ `Cracker` will attempt to use as many `Crackling`s, in re-cracking sessions, for an `IsoRing` as program
86
+ permits until `Cracker` cracks its wanted local optimum from the suspected `Sec` of said `IsoRing`.
87
+
88
+ A structure called a `SearchSpaceIterator` is employed by every `Crackling` to execute brute-force
89
+ cracking attempts on an `IsoRing`'s isomorphic representation. `SearchSpaceIterator` outputs `k x h`
90
+ points that uniformly cover the input bounds of matrix `k x 2`.
91
+
92
+ If the `Cracker` does not a `HypStruct` for the `IsoRing`'s isomorphic representation (the second
93
+ layer in the three-layer hypothesis map), program halts `Cracker` midway. If the `Crackling` is
94
+ successful in cracking the isomorphic representation, `IsoRing` has to switch its isomorphic representation
95
+ to an uncracked `Sec`. If there are none that have not been cracked, `IsoRing` stops switching its
96
+ isomorphic representation due to the `Cracker` no longer being interested in cracking it anymore.
97
+
98
+ If a `Crackling` does not produce any (vector, associated probability value) on a `Sec`, `Cracker` cannot
99
+ proceed to attempting to crack any `IsoRing`s dependent on the `IsoRing`, pertaining to said `Sec`, being
100
+ cracked. In most cases, `Cracker` would be halted.
101
+
102
+ # The Brute-Force Environment
103
+
104
+ There Are Rules To The Game. The rules are enforced in the environment `BruteForceEnv`, where a `Cracker`
105
+ attempts to crack an `IsoRingedChain`. A `Cracker` is granted some arbitrary amount of energy, a real number.
106
+ If the energy falls to zero or below, program halts `Cracker`. A `Cracker` can use only `t` number of
107
+ `Crackling`s at once. If there are co-dependent `IsoRing` sets in `IsoRingedChain` that are greater in size
108
+ than `t`, successfully cracking the `IsoRingedChain` is impossible for the `Cracker`.
109
+
110
+ # What is Successful Cracking? Complete Execution or Complete Acquisition of Actual?
111
+
112
+ The complete execution of cracking all the `IsoRing`s in an `IsoRingedChain` can be known by a `Cracker` by
113
+ the time the program halts `Cracker`. However, the `BackgroundInfo` of a `Cracker` is what allows it to verify
114
+ on what the actual vectors from `IsoRingedChain` are.
115
+
116
+ # Additional Features
117
+
118
+ Generative methods, found in this program, can be used to produce the relevant data structures. These
119
+ methods do come in handy since there are a lot of variables to type up by hand.
120
+
121
+ # An Example On the User Interface
122
+
123
+ ![Screenshot](screeshantaya.png)
File without changes
File without changes
@@ -0,0 +1,172 @@
1
+ from .hypothesis import *
2
+ from ..secrets.big_secret import *
3
+
4
+
5
+ def prng_to_decimal_output(prng):
6
+
7
+ def f():
8
+ q1 = abs(prng())
9
+ q2 = abs(prng())
10
+ if q1 == 0 or q2 == 0: return 0.0
11
+
12
+ if q1 < q2: return q1 / q2
13
+ return q2 / q1
14
+ return f
15
+
16
+ # NOTE: this prng must exclusively output integers
17
+ def n_swaps_on_seq(seq,n,prng):
18
+
19
+ ix = [_ for _ in range(len(seq))]
20
+ ix = prg_seqsort(ix,prng)
21
+
22
+ for i in range(n):
23
+ # pop index
24
+ index = ix[i%len(ix)]
25
+ x = seq.pop(index)
26
+
27
+ # re-insert
28
+ index = prng() % (len(seq) +1)
29
+
30
+ seq.insert(index,x)
31
+ return seq
32
+
33
+ class BackgroundInfo:
34
+
35
+ """
36
+ info := dict, <Isoring> identifier -> <Sec> index -> <HypStruct>
37
+ suspected_isoring_to_sec_idn := dict, <IsoRing> -> index of <Sec> most likely to be solution.
38
+ order_of_cracking := list, of sets of <IsoRing> identifiers, specifying the
39
+ order that a <Cracker> will attempt cracking an <IsoRingedChain>.
40
+ """
41
+ # NOTE: `suspected_isoring_to_sec_idn` can be incomplete w.r.t. `info`. In these cases,
42
+ # <BackgroundInfo> uses method<default_most_likely_Sec_index_for_IsoRing> to decide
43
+ # the best <HypStruct>.
44
+ def __init__(self,info:dict,suspected_isoring_to_sec_idn:dict,order_of_cracking:list):
45
+ assert BackgroundInfo.verify_valid_info(info)
46
+
47
+ q = set(info.keys())
48
+ c = set()
49
+ for o in order_of_cracking: c |= o
50
+ assert q == c
51
+
52
+ self.info = info
53
+ self.suspected_isoring_to_sec_idn = suspected_isoring_to_sec_idn
54
+ self.order_of_cracking = order_of_cracking
55
+ return
56
+
57
+ def hypothesis_for_IsoRingANDSec(self,i,s):
58
+ if not self.hypothesis_exists_for_IsoRingANDSec(i,s):
59
+ return None
60
+ return self.info[i][s]
61
+
62
+ def hypothesis_exists_for_IsoRingANDSec(self,i,s):
63
+ if i not in self.info:
64
+ return False
65
+
66
+ if s not in self.info[i]:
67
+ return False
68
+ return True
69
+
70
+ @staticmethod
71
+ def verify_valid_info(info):
72
+ for k,v in info.items():
73
+ if not type(k) == int: return False
74
+ for k2,v2 in v.items():
75
+ if not type(k2) == int: return False
76
+ if not type(v2) == HypStruct: return False
77
+ return True
78
+
79
+ # TODO: test this.
80
+ @staticmethod
81
+ def extract_from_IsoRingedChain(irc,prng,actual_sec_vec_ratio_range,dim_covered_ratio_range,\
82
+ valid_bounds_ratio_range,prioritize_actual_Sec_ratio,shuffle_OOC_ratio,\
83
+ suspected_isoring_to_sec_idn_error_ratio,valid_one_shot_kill_ratio_range=[0.,0.]):
84
+ assert type(irc) == IsoRingedChain
85
+ assert 0. <= actual_sec_vec_ratio_range[0] <= actual_sec_vec_ratio_range[1] <= 1.
86
+ assert 0. <= dim_covered_ratio_range[0] <= dim_covered_ratio_range[1] <= 1.
87
+ assert 0. <= valid_bounds_ratio_range[0] <= valid_bounds_ratio_range[1] <= 1.
88
+ assert 0. <= prioritize_actual_Sec_ratio <= 1.0
89
+ assert 0. <= shuffle_OOC_ratio <= 1.0
90
+ assert 0. <= suspected_isoring_to_sec_idn_error_ratio <= 1.0
91
+
92
+ def prg_(): return int(prng())
93
+
94
+ prng_dec = prng_to_decimal_output(prng)
95
+
96
+ info = dict()
97
+ for idn_tag,ir in irc.ir_dict.items():
98
+ # fetch all ratios and bools
99
+ if actual_sec_vec_ratio_range[0] == actual_sec_vec_ratio_range[1]:
100
+ actual_sec_vec_ratio = actual_sec_vec_ratio_range[0]
101
+ else:
102
+ actual_sec_vec_ratio = modulo_in_range(prng_dec(),actual_sec_vec_ratio_range)
103
+
104
+ if dim_covered_ratio_range[0] == dim_covered_ratio_range[1]:
105
+ ratio_of_dim_covered = dim_covered_ratio_range[0]
106
+ else:
107
+ ratio_of_dim_covered = modulo_in_range(prng_dec(),dim_covered_ratio_range)
108
+
109
+ if valid_bounds_ratio_range[0] == valid_bounds_ratio_range[1]:
110
+ valid_bounds_ratio = valid_bounds_ratio_range[0]
111
+ else:
112
+ valid_bounds_ratio = modulo_in_range(prng_dec(),valid_bounds_ratio_range)
113
+
114
+ if valid_one_shot_kill_ratio_range[0] == valid_one_shot_kill_ratio_range[1]:
115
+ valid_one_shot_kill_ratio = valid_one_shot_kill_ratio_range[0]
116
+ else:
117
+ valid_one_shot_kill_ratio = modulo_in_range(prng_dec(),valid_one_shot_kill_ratio_range)
118
+
119
+ prioritize_actual_Sec = prng_dec() <= prioritize_actual_Sec_ratio
120
+
121
+ hdict = HypStruct.extract_from_IsoRing_into_HypStruct_dict(ir,prng,actual_sec_vec_ratio,\
122
+ ratio_of_dim_covered,valid_bounds_ratio,prioritize_actual_Sec,valid_one_shot_kill_ratio)
123
+ info[idn_tag] = hdict
124
+
125
+ # get the IsoRing identifiers for the IsoRing to Sec index error
126
+ i2s_error = int(ceil(suspected_isoring_to_sec_idn_error_ratio * len(info)))
127
+ L = sorted(info.keys())
128
+ L = prg_seqsort(L,prg_)[:i2s_error]
129
+ S = dict()
130
+ for k in info.keys():
131
+ ir = irc.fetch_IsoRing(k)
132
+
133
+ # case: correct <Sec> index
134
+ actual = ir.actual_sec_index
135
+ if k not in L:
136
+ S[k] = actual
137
+ else:
138
+ qs = [_ for _ in range(len(ir.sec_list)) if _ != actual]
139
+
140
+ # case: no alternative Sec, use actual
141
+ if len(qs) == 0:
142
+ S[k] = actual
143
+ else:
144
+ qi = prg_() % len(qs)
145
+ S[k] = qs[qi]
146
+
147
+ # get the OOC
148
+ num_swaps = int(ceil(shuffle_OOC_ratio * len(irc.ooc)))
149
+ ooc = n_swaps_on_seq(deepcopy(irc.ooc),num_swaps,prg_)
150
+
151
+ return BackgroundInfo(info,S,ooc)
152
+
153
+ def sec_index_for_IsoRing(self,ir_idn):
154
+ if ir_idn not in self.suspected_isoring_to_sec_idn:
155
+ return self.default_most_likely_Sec_index_for_IsoRing(ir_idn)
156
+ return self.suspected_isoring_to_sec_idn[ir_idn]
157
+
158
+ """
159
+ chooses the <Sec> index with a <HypStruct> of highest probability marker.
160
+ """
161
+ def default_most_likely_Sec_index_for_IsoRing(self,ir_idn):
162
+ if ir_idn not in self.info: return None
163
+
164
+ d = self.info[ir_idn]
165
+ if len(d) == 0: return None
166
+
167
+ secindex_pr = []
168
+ for k,v in d.items():
169
+ secindex_pr.append((k,v.probability_marker))
170
+
171
+ secindex_pr = sorted(secindex_pr,key=lambda x:x[1],reverse=True)
172
+ return secindex_pr[0][0]
@@ -0,0 +1,133 @@
1
+ from .cracker import *
2
+
3
+ def one_to_one_IsoRing2Crackling_map(ir_idn:set):
4
+ assert type(ir_idn) == set
5
+ return {i:1 for i in ir_idn}
6
+
7
+ """
8
+ environment for a Cracker, given background information on an IsoRingedChain, to conduct brute-force guesses
9
+ against it.
10
+ """
11
+ class BruteForceEnv:
12
+
13
+ def __init__(self,crck:Cracker,irc:IsoRingedChain,prng=None,verbose=True):
14
+ assert type(crck) == Cracker and type(irc) == IsoRingedChain
15
+ assert type(verbose) == bool
16
+ self.crck = crck
17
+ self.irc = irc
18
+
19
+ if type(prng) == type(None):
20
+ self.prng = default_std_Python_prng(output_range=[-10000,10000],rounding_depth=0)
21
+ else:
22
+ self.prng = prng
23
+ self.irc.prng = self.prng
24
+ self.verbose = verbose
25
+
26
+ self.cbridges = []
27
+
28
+ self.num_iter = 0
29
+ return
30
+
31
+ def __next__(self):
32
+ # case: finished
33
+ if self.is_finished(): return
34
+
35
+ # if no CBridges exist, declare them
36
+ if len(self.cbridges) == 0:
37
+ stat = self.first_cracking_bridges()
38
+ if not stat:
39
+ return
40
+
41
+ self.run_cbridges()
42
+ self.num_iter += 1
43
+ return
44
+
45
+ # TODO: finish
46
+ def is_finished(self):
47
+ if self.crck.halted:
48
+ return True
49
+ return False
50
+
51
+ def run_cbridges(self):
52
+ any_terminated = False
53
+
54
+ i = 0
55
+ while i < len(self.cbridges):
56
+ c = self.cbridges[i]
57
+ if c.terminated:
58
+ any_terminated = True
59
+ self.cbridges.pop(i)
60
+ continue
61
+ next(c)
62
+ i += 1
63
+
64
+
65
+ if any_terminated:
66
+
67
+ wanted_finishes,recracks = self.crck.manage_cracklings()
68
+ if self.verbose:
69
+ print("# BRIDGES: ",len(self.cbridges))
70
+ print("\t- finished cracking on IsoRings\n{}".format(wanted_finishes))
71
+ print("\t- recracking on IsoRings\n{}".format(recracks))
72
+ print("=======================================================")
73
+
74
+ self.send_IsoRingedChain_info_on_cracked(wanted_finishes,recracks)
75
+
76
+ if len(recracks) > 0:
77
+ self.add_recracking_bridges(recracks)
78
+
79
+ self.crck.did_fail()
80
+
81
+ def first_cracking_bridges(self):
82
+ stat = self.crck.next_target_IsoRing_set()
83
+
84
+ if self.verbose:
85
+ print("[!] t={}, Adding initial cracking bridges to IsoRings\n{}\n".format(self.num_iter,self.crck.target_ir_set))
86
+
87
+ # case: no new targets, terminated
88
+ if not stat:
89
+ if self.verbose: print("[X] no new target IsoRings. DONE.")
90
+ self.crck.halted = True
91
+ return stat
92
+
93
+ # case: wrong order, IsoRingedChain does not accept
94
+ stat = self.irc.accept_cracker_targetset(self.crck.target_ir_set)
95
+ if not stat:
96
+ if self.verbose: print("[X] wrong cracking order. DONE.")
97
+ self.crck.halted = True
98
+ return stat
99
+
100
+ stat = self.initiate_Cracker_deployment(self.crck.target_ir_set)
101
+
102
+ self.crck.increment_index()
103
+ return stat
104
+
105
+ def add_recracking_bridges(self,recrack_set):
106
+ assert recrack_set.issubset(self.crck.target_ir_set)
107
+ return self.initiate_Cracker_deployment(recrack_set)
108
+
109
+ def initiate_Cracker_deployment(self,ir_set):
110
+
111
+ # send Cracker info on IsoRing iso-repr state
112
+ ir_state = self.irc.repr_dict_for_IsoRings(ir_set)
113
+ i2c_map = one_to_one_IsoRing2Crackling_map(ir_set)
114
+
115
+ stat = self.crck.deploy_cracklings(ir_state,i2c_map)
116
+
117
+ # case: Cracker is stuck.
118
+ if not stat:
119
+ self.crck.halted = True
120
+ return stat
121
+
122
+ # form the bridges
123
+ q = -sum(i2c_map.values())
124
+ for cr in self.crck.active_cracklings[q:]:
125
+ hs = self.crck.bi.hypothesis_for_IsoRingANDSec(cr.target_ir,cr.ir_sec_index)
126
+ ir = self.irc.fetch_IsoRing(cr.target_ir)
127
+ cb = CBridge(cr,hs,ir)
128
+ self.cbridges.append(cb)
129
+ return True
130
+
131
+ def send_IsoRingedChain_info_on_cracked(self,wanted_finishes,recracks):
132
+ self.irc.register_cracked_IsoRings(wanted_finishes,recracks)
133
+ return