(chars, function, show=50, format_="%s")
| 2 | |
| 3 | |
| 4 | def findPassword(chars, function, show=50, format_="%s"): |
| 5 | password = None |
| 6 | attempts = 0 |
| 7 | size = 1 |
| 8 | stop = False |
| 9 | |
| 10 | while not stop: |
| 11 | # Obtém todas as combinações possíveis com os dígitos do parâmetro "chars". |
| 12 | for pw in product(chars, repeat=size): |
| 13 | password = "".join(pw) |
| 14 | |
| 15 | # Imprime a senha que será tentada. |
| 16 | if attempts % show == 0: |
| 17 | print(format_ % password) |
| 18 | |
| 19 | # Verifica se a senha é a correta. |
| 20 | if function(password): |
| 21 | stop = True |
| 22 | break |
| 23 | else: |
| 24 | attempts += 1 |
| 25 | size += 1 |
| 26 | |
| 27 | return password, attempts |
| 28 | |
| 29 | |
| 30 | def getChars(): |
no test coverage detected