|
11 | 11 | HASH_ITERS = 100
|
12 | 12 | ITERS_TOADD = 10
|
13 | 13 | ENC_CODE_POS = 0
|
14 |
| -HEX_POS_LEN = 2 |
15 |
| -ENC_LIST_LEN = 216 if HEX_POS_LEN == 2 else 600 # 10^2 * 6 |
| 14 | +HEX_POS_LEN = 3 |
| 15 | +ENC_LIST_LEN = (6**2)*6 if HEX_POS_LEN == 2 else (26**2)*6 |
16 | 16 | TEXT_LEN_POS = [1,2,3]
|
17 | 17 |
|
18 | 18 | ##########################################################################################################
|
@@ -70,29 +70,21 @@ def encrypt(txt, pwd):
|
70 | 70 | # Initial number of iterations for the hash
|
71 | 71 | iters = HASH_ITERS
|
72 | 72 |
|
73 |
| - # Combine 3 consecutive hashes, created from the initial hash |
| 73 | + # Create a new hash from the old hash |
74 | 74 | hash = h2h(hash, iters)
|
75 | 75 |
|
76 | 76 | # Add ITERS_TOADD to the iterations count
|
77 | 77 | iters += ITERS_TOADD
|
78 | 78 |
|
79 |
| - while True: |
80 |
| - # Convert each pair of hex digits from the hash to an integer (but the result has to be below ENC_LIST_LEN) |
81 |
| - pwd_indexes = [] |
| 79 | + pwd_indexes = [] |
| 80 | + while len(pwd_indexes) < ENC_LIST_LEN: |
82 | 81 | for i in range(0, len(hash), HEX_POS_LEN):
|
83 | 82 | n = int(hash[i : i+HEX_POS_LEN], 16)
|
84 | 83 | if n < ENC_LIST_LEN and n not in pwd_indexes:
|
85 | 84 | pwd_indexes.append(n)
|
86 |
| - |
87 |
| - # If the list has more than the required length, break (end the loop) |
88 |
| - if len(pwd_indexes) >= ENC_LIST_LEN: |
89 |
| - break |
90 |
| - |
91 |
| - # If the list doesn't have enough indexes, add other hash to the hash |
92 |
| - hash += h2h(hash, iters) |
93 |
| - |
94 |
| - # Increase the iterations count by ITERS_TOADD |
95 | 85 | iters += ITERS_TOADD
|
| 86 | + hash = h2h(hash, iters) |
| 87 | + print(len(pwd_indexes)) |
96 | 88 |
|
97 | 89 | # Create a new hash to use to obtain the symbols used in the encryption and their order
|
98 | 90 | hash = h2h(hash, iters)
|
@@ -154,29 +146,20 @@ def decrypt(txt,pwd):
|
154 | 146 | # Initial number of iterations for the hash
|
155 | 147 | iters = HASH_ITERS
|
156 | 148 |
|
157 |
| - # Combine 3 consecutive hashes, created from the initial hash |
| 149 | + # Create a new hash from the old hash |
158 | 150 | hash = h2h(hash, iters)
|
159 | 151 |
|
160 | 152 | # Add ITERS_TOADD to the iterations count
|
161 | 153 | iters += ITERS_TOADD
|
162 | 154 |
|
163 |
| - while True: |
164 |
| - # Convert each pair of hex digits from the hash to an integer (but the result has to be below ENC_LIST_LEN) |
165 |
| - pwd_indexes = [] |
| 155 | + pwd_indexes = [] |
| 156 | + while len(pwd_indexes) < ENC_LIST_LEN: |
166 | 157 | for i in range(0, len(hash), HEX_POS_LEN):
|
167 | 158 | n = int(hash[i : i+HEX_POS_LEN], 16)
|
168 | 159 | if n < ENC_LIST_LEN and n not in pwd_indexes:
|
169 | 160 | pwd_indexes.append(n)
|
170 |
| - |
171 |
| - # If the list has more than the required length, break (end the loop) |
172 |
| - if len(pwd_indexes) >= ENC_LIST_LEN: |
173 |
| - break |
174 |
| - |
175 |
| - # If the list doesn't have enough indexes, add other hash to the hash |
176 |
| - hash += h2h(hash, iters) |
177 |
| - |
178 |
| - # Increase the iterations count by ITERS_TOADD |
179 | 161 | iters += ITERS_TOADD
|
| 162 | + hash = h2h(hash, iters) |
180 | 163 |
|
181 | 164 | # Create a new hash to use to obtain the symbols used in the encryption and their order
|
182 | 165 | hash = h2h(hash, iters)
|
|
0 commit comments