@@ -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 )
0 commit comments