Brute force script in Python 3.2

狂风中的少年 提交于 2019-11-30 10:04:38

Code first:

from itertools import product

chars = '0123456789' # chars to look for

for length in range(1, 3): # only do lengths of 1 + 2
    to_attempt = product(chars, repeat=length)
    for attempt in to_attempt:
        print(''.join(attempt))

itertools.product produces a Cartesian join of its input(s) - in this case, it's being 'joined' to itself. So in the first iteration, each single character is printed. Then in the next iteration, because of repeat=length (and length is now == 2), generates '00', '01', etc... It's worth trying it and seeing the output to understand it better.

This also means you can throw in letters (uppercase/lowercase), and change the upperbound in the range function.

It's certainly not going to break the world of code-breaking, but should give you an idea of the flexibility of Python and the tools available to you.

I'll leave you to check the passwords match and break out the loop.

You want something like this:

PassWord = str(random.randint(0,9999))#example password 
for i in range(10000):    #0-9999
   Trial = str(i)  
   if Trial == Password:  
       print('Found password: ' + Password) 
import random

digits=list(range(0,1000))
password=random.randint(0,1000)
eachdigit=-1
print(password)
while eachdigit!=password:
    for eachdigit in digits:
        print(eachdigit)
        if eachdigit==password:
            print("Password is found:"+str(eachdigit)+"---------------------------")
            password=str(input("Enter new password if you wish"))

This is what I have done, it is extremely ineffective and badly written, I am currently trying to put it into a function so it will do any length but it only does 4 atm. I used a string of letters/numbers and ran through that in sequence until answer = password:

idea = ["a","b","c","d","e","1","2","3",.........]
var = 0
answer = ""

while answer != password:
     answer = idea[var]
     print(answer)
     var += 1

If you value your eyes don't look below (warning you it is messy).

<pre><code>
password = input("pass:")
#idea = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9"," "]
#THE IDEA ABOVE IS THE FULL A-Z, 0-9 (takes ages)
password = input("pass:")
idea = ["a","b","c","d"]
awnser = [""] *6
var = 0
var1 = 0
var2 = 0
var3 = 0
char = 0

while awnser != password:
    awnser = idea[var]
    print(awnser)
    if var != len(idea):
        var += 1
    if var == len(idea):
        var = 0
        while awnser != password:
            awnser = idea[var]+idea[var1]
            print(awnser)
            if var != len(idea):
                var += 1
            if var == len(idea):
                if var1 != len(idea):
                    var = 0
                    var1 += 1
                if var1 == len(idea):
                    var = 0
                    var1 = 0
                    while awnser != password:
                        awnser = idea[var]+idea[var1]+idea[var2]
                        print(awnser)
                        if var != len(idea):
                            var += 1
                        if var == len(idea):
                            if var1 != len(idea):
                                var = 0
                                var1 += 1
                            if var1 == len(idea):
                                if var2 != len(idea):
                                    var = 0
                                    var1 = 0
                                    var2 += 1
                                if var2 == len(idea):
                                    var = 0
                                    var1 = 0
                                    var2 = 0
                                    while awnser != password:
                                        awnser = idea[var]+idea[var1]+idea[var2]+idea[var3]
                                        print(awnser)
                                        if var != len(idea):
                                            var += 1
                                        if var == len(idea):
                                            if var1 != len(idea):
                                                var = 0
                                                var1 += 1
                                            if var1 == len(idea):
                                                if var2 != len(idea):
                                                    var = 0
                                                    var1 = 0
                                                    var2 += 1
                                                if var2 == len(idea):
                                                    print("==============================================")
                                                    print("Password too long or characters not in string!")
                                                    print("==============================================")
                                                    break

print("==================")
print("")
input("Password = "+awnser)



</code></pre>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!