Fork me on GitHub
pikachu's Blog

sha256(py2 vs py3)

前言
sha256 工作量证明,python2python3 的不同

python2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def sha256_pj(prefix):

chars = ''.join(chr(i) for i in range(32,127)[::-1])
for password_length in range(4,5):
for iteration in itertools.product(chars, repeat=password_length):
iteration = ''.join(iteration)
h = hashlib.sha256()
h.update(prefix.encode() + iteration)

bits = ''.join(bin(int(i, 16))[2:].zfill(4) for i in h.hexdigest())
print iteration, bits[:18]

if bits[:18] == "0"*18:
print "The password is: " + iteration
return iteration

python3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import hashlib,itertools

def sha256_pj(prefix):

chars = ''.join(chr(i) for i in range(32,127)[::-1])
for password_length in range(4,5):
for iteration in itertools.product(chars, repeat=password_length):
iteration = ''.join(iteration)
h = hashlib.sha256()
h.update((prefix + iteration).encode())

bits = ''.join(bin(i)[2:].zfill(8) for i in h.digest())
print(iteration, bits[:18])

if bits[:18] == "0"*18:
print("The password is: " + iteration)
return iteration
---------------- The End ----------------
谢谢大爷~

Author:pikachu
Link:https://hitcxy.com/2020/sha256/
Contact:hitcxy.cn@gmail.com
本文基于 知识共享署名-相同方式共享 4.0 国际许可协议发布
转载请注明出处,谢谢!