Skip to content

Commit 9597a64

Browse files
committed
formatting
*formatting
1 parent 373b937 commit 9597a64

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

pydatastructs/strings/algorithms.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ def sha256_encrypt(text) -> str:
274274
Examples
275275
========
276276
277-
>>> from pydatastructs.strings.algorithms import Crypto
277+
>>> from pydatastructs import Crypto
278278
>>> text = "PyDataStructs"
279279
>>> ciphertext = Crypto.sha256_encrypt(text)
280280
>>> print(ciphertext)
281-
"777a305fe4f1cfc7ce270891ec50651331e2ab6d09312b906740a5ea413bd057"
281+
777a305fe4f1cfc7ce270891ec50651331e2ab6d09312b906740a5ea413bd057
282282
283283
References
284284
==========
@@ -298,39 +298,39 @@ def sha256_encrypt(text) -> str:
298298
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
299299
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
300300
]
301-
301+
302302
h = [
303303
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
304304
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
305305
]
306-
306+
307307
message = bytearray(text, 'utf-8')
308308
length = len(message) * 8
309309
message.append(0x80)
310310
while (len(message) * 8) % 512 != 448:
311311
message.append(0)
312312
message += struct.pack('>Q', length)
313-
313+
314314
for i in range(0, len(message), 64):
315315
chunk = message[i:i+64]
316316
w = list(struct.unpack('>16L', chunk)) + [0] * 48
317317
for j in range(16, 64):
318318
s0 = (Crypto._right_rotate(w[j-15], 7) ^ Crypto._right_rotate(w[j-15], 18) ^ (w[j-15] >> 3))
319319
s1 = (Crypto._right_rotate(w[j-2], 17) ^ Crypto._right_rotate(w[j-2], 19) ^ (w[j-2] >> 10))
320320
w[j] = (w[j-16] + s0 + w[j-7] + s1) & 0xFFFFFFFF
321-
321+
322322
a, b, c, d, e, f, g, h0 = h
323-
323+
324324
for j in range(64):
325325
S1 = Crypto._right_rotate(e, 6) ^ Crypto._right_rotate(e, 11) ^ Crypto._right_rotate(e, 25)
326326
ch = (e & f) ^ (~e & g)
327327
temp1 = (h0 + S1 + ch + k[j] + w[j]) & 0xFFFFFFFF
328328
S0 = Crypto._right_rotate(a, 2) ^ Crypto._right_rotate(a, 13) ^ Crypto._right_rotate(a, 22)
329329
maj = (a & b) ^ (a & c) ^ (b & c)
330330
temp2 = (S0 + maj) & 0xFFFFFFFF
331-
331+
332332
h0, g, f, e, d, c, b, a = (g, f, e, (d + temp1) & 0xFFFFFFFF, c, b, a, (temp1 + temp2) & 0xFFFFFFFF)
333-
333+
334334
h = [(x + y) & 0xFFFFFFFF for x, y in zip(h, [a, b, c, d, e, f, g, h0])]
335-
336-
return ''.join(f'{value:08x}' for value in h)
335+
336+
return ''.join(f'{value:08x}' for value in h)

pydatastructs/strings/tests/test_algorithms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def gen_random_string(length):
7676
assert positions.size == 0
7777

7878
def _test_sha256_encrypt():
79-
79+
8080
test_cases = [
8181
"HelloWorld",
8282
"1234567890",
@@ -85,7 +85,7 @@ def _test_sha256_encrypt():
8585
"The quick brown fox jumps over the lazy dog",
8686
"Pydatastructs"
8787
]
88-
88+
8989
expected_hashes = [
9090
"872e4e50ce9990d8b041330c47c9ddd11bec6b503ae9386a99da8584e9bb12c4",
9191
"c775e7b757ede630cd0aa1113bd102661ab38829ca52a6422ab782862f268646",
@@ -94,6 +94,6 @@ def _test_sha256_encrypt():
9494
"d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592",
9595
"1b5b22944c188c3e90d126ebd27e10d7497fbf5924f23c05775fa2dd9e1d8c86"
9696
]
97-
97+
9898
for text, expected in zip(test_cases, expected_hashes):
99-
assert Crypto.sha256_encrypt(text) == expected
99+
assert Crypto.sha256_encrypt(text) == expected

0 commit comments

Comments
 (0)