ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Python练习题答案: 真正的密码破解者【难度:2级】--景越Python编程实例训练营,1000道上机题等你来挑战

2019-09-06 09:35:24  阅读:256  来源: 互联网

标签:练习题 hashlib hash 景越 Python product return itertools import


真正的密码破解者【难度:2级】:

答案1:

import hashlib
import itertools

def password_cracker(hash):
    for length in range(6):
        for candidate in map("".join, itertools.product("abcdefghijklmnopqrstuvwxyz", repeat=length)):
            if hashlib.sha1(candidate.encode()).hexdigest() == hash:
                return candidate​

答案2:

from binascii import unhexlify
from hashlib import sha1
from itertools import product
from string import ascii_lowercase

def password_cracker(hash):
    b = unhexlify(hash)
    for i in range(6):
        for xs in product(ascii_lowercase.encode(), repeat=i):
            if sha1(bytes(xs)).digest() == b:
                return ''.join(bytes(xs).decode())​

答案3:

import hashlib
import itertools
def password_cracker(hash):
    q='abcdefghijklmnopqrstuvwxyz'
    for g in range(0,5):
        for test in itertools.product(q,repeat=g):
            if hashlib.sha1(''.join(test).encode('utf-8')).hexdigest()==hash: return ''.join(test)
    for s in q:
      for test in itertools.product(q,repeat=4):
        if hashlib.sha1((s+''.join(test)).encode('utf-8')).hexdigest()==hash: return s+''.join(test)
​

答案4:

from hashlib import sha1
from itertools import product
from string import ascii_lowercase as alc

hash_gen = ((code, sha1(code.encode()).hexdigest()) for code in (''.join(p) for r in range(6) for p in product(alc, repeat=r)))
rainbow = {}

def password_cracker(hash):
    code = rainbow.get(hash, None)
    if code is not None:
        return code
    for code, h in hash_gen:
        rainbow[h] = code
        if h == hash:
            return code​

答案5:

import string
import itertools
import hashlib

def password_cracker(hash):
    chars = string.ascii_lowercase
    for password_length in range(0, 6):
        for guess in itertools.product(chars, repeat=password_length):
            guess = ''.join(guess)
            result = hashlib.sha1(guess.encode()) 
            if result.hexdigest() == hash:
                return guess​

答案6:

import itertools
import string
import hashlib

def password_cracker(hash):
    generating = True
    minlength = 0
    while generating:
        for subset in itertools.product(string.ascii_lowercase, repeat=minlength):
            word = ''.join(subset)
            if hash == gethash(word.encode()):
                return word
        minlength +=1
        if minlength > 5:
            generating = False
    return ''
                 
def gethash(word):
    hash_object = hashlib.sha1(word)
    pbHash = hash_object.hexdigest()
    return str(pbHash)​

答案7:

import string
import hashlib
from itertools import product

def password_cracker(hash):
    alphabet = string.ascii_lowercase
    
    for long in range(6):
    
        cases = product(alphabet, repeat = long)
    
        for case in cases:
        
            temp_hash = hashlib.sha1(''.join(case).encode('utf-8')).hexdigest()
            
            if(hash == temp_hash):
                return ''.join(case)​

答案8:

from itertools import product as P
from hashlib import sha1 as S
def password_cracker(h,A='abcdefghijklmnopqrstuvwxyz'):
    for i in range(6):
        for x in map(''.join,P(A,repeat=i)):
            if S(x.encode('ascii')).hexdigest()==h:return x​

答案9:

import hashlib
from itertools import product
from string import ascii_lowercase


def password_cracker(hash):
    for n in range(0,6):
        all = (''.join(i) for i in product(ascii_lowercase, repeat = n))
        for item in all:
            hash_object = hashlib.sha1(bytearray(item, 'utf-8'))
            check = hash_object.hexdigest()
            if check == hash:
                return item
                break​

答案10:

import hashlib
from itertools import product
from string import ascii_lowercase


def password_cracker(hash):
    for n in range(0,6):
        all = (''.join(i) for i in product(ascii_lowercase, repeat = n))
        for item in all:
            hash_object = hashlib.sha1(bytearray(item, 'utf-8'))
            check = hash_object.hexdigest()
            if check == hash:
                return item
                break
#     return "Password Not Found"
    
print(password_cracker('e6fb06210fafc02fd7479ddbed2d042cc3a5155e'))​

标签:练习题,hashlib,hash,景越,Python,product,return,itertools,import
来源: https://blog.csdn.net/aumtopsale/article/details/100572414

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有