Skip to content

Commit f41ae76

Browse files
authoredJun 18, 2022
Add files via upload
1 parent c81123d commit f41ae76

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed
 

‎img.png

1.89 KB
Loading

‎main.py

+11-28
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
HASH_ITERS = 100
1212
ITERS_TOADD = 10
1313
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
1616
TEXT_LEN_POS = [1,2,3]
1717

1818
##########################################################################################################
@@ -70,29 +70,21 @@ def encrypt(txt, pwd):
7070
# Initial number of iterations for the hash
7171
iters = HASH_ITERS
7272

73-
# Combine 3 consecutive hashes, created from the initial hash
73+
# Create a new hash from the old hash
7474
hash = h2h(hash, iters)
7575

7676
# Add ITERS_TOADD to the iterations count
7777
iters += ITERS_TOADD
7878

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:
8281
for i in range(0, len(hash), HEX_POS_LEN):
8382
n = int(hash[i : i+HEX_POS_LEN], 16)
8483
if n < ENC_LIST_LEN and n not in pwd_indexes:
8584
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
9585
iters += ITERS_TOADD
86+
hash = h2h(hash, iters)
87+
print(len(pwd_indexes))
9688

9789
# Create a new hash to use to obtain the symbols used in the encryption and their order
9890
hash = h2h(hash, iters)
@@ -154,29 +146,20 @@ def decrypt(txt,pwd):
154146
# Initial number of iterations for the hash
155147
iters = HASH_ITERS
156148

157-
# Combine 3 consecutive hashes, created from the initial hash
149+
# Create a new hash from the old hash
158150
hash = h2h(hash, iters)
159151

160152
# Add ITERS_TOADD to the iterations count
161153
iters += ITERS_TOADD
162154

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:
166157
for i in range(0, len(hash), HEX_POS_LEN):
167158
n = int(hash[i : i+HEX_POS_LEN], 16)
168159
if n < ENC_LIST_LEN and n not in pwd_indexes:
169160
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
179161
iters += ITERS_TOADD
162+
hash = h2h(hash, iters)
180163

181164
# Create a new hash to use to obtain the symbols used in the encryption and their order
182165
hash = h2h(hash, iters)

0 commit comments

Comments
 (0)