我是编写代码的初学者,我从Python开始,因为它似乎是最开始的最简单(我目前有Python 3.2)。现在我已经阅读了一些有关python编码的在线书籍,我已经制作了一些小程序,就是这样。
但后来我想创建一个可以强制输入随机密码的程序,如:
PassWord = random.randint(0,9999)
我做了一些可以尝试随机密码的东西:
import random
PassWord = str(random.randint(0,9999))
Trial = ' '
while Trial != PassWord:
Trial = str(random.randint(0,9999))
print(Trial)
if Trial == PassWord:
print('The password is: '+PassWord)
input()
但这不是真正的暴力攻击,它更多的是试图随机猜测密码。我认为暴力攻击首先尝试所有可能性的1位数,然后是2,3位,依此类推。但我不知道如何做到这一点。
我真的很感激,如果有人会说如何创建一个程序,首先用1位数检查所有可能性,如果可能的话,以正确的顺序(0,1,2,3等等),然后2,3和4位数。
然后我可以解决它,并了解有关Python的更多信息。
答案 0 :(得分:14)
代码优先:
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
生成其输入的笛卡尔连接 - 在这种情况下,它与自身“连接”。所以在第一次迭代中,每个单个字符都被打印出来。然后在下一次迭代中,由于repeat=length
(而length
现在== 2),生成'00','01'等等...值得尝试并看到输出要理解它更好。
这也意味着您可以输入字母(大写/小写),并更改range
函数中的上限。
这肯定不会破坏破解代码的世界,但应该让您了解Python的灵活性以及可用的工具。
我会让你检查密码匹配并打破循环。
答案 1 :(得分:2)
你想要这样的东西:
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)
答案 2 :(得分:0)
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"))
答案 3 :(得分:0)
只要运行这个程序,你就会得到你想要的。 但请记住更改我在代码中注释的字段的值。
import random
import time
import os
from tqdm import tqdm
import random
import getpass
def loading():
for index in tqdm(range(100), desc = "loading..."):
time.sleep(0.1)
pss = random.randint(1, 9)
print("found a digit-", pss)
print("hunt will continue in 2 seconds...")
def pas():
pas = getpass.getpass("enter password: ")
if pas == ("root"): #you can change it according to your need
menu()
else:
end()
def login():
usid = input("enter username: ")
if usid == ("root"): #change this too according to your need
pas()
else:
end()
def end():
os.system('cls')
print("okk!! bye...")
exit()
def menu():
os.system('cls')
input("enter ip address:")
os.system('cls')
print("starting the hunt...")
time.sleep(2)
os.system('cls')
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
time.sleep(2)
loading()
print("completed! combine the digits and that's your password...")
end()
login()
答案 4 :(得分:-1)
这就是我所做的,它非常无效且编写得很糟糕,我目前正试图把它放入一个函数中,所以它会做任何长度,但它只做4个大气压。我使用了一串字母/数字并按顺序浏览,直到answer = password:
idea = ["a","b","c","d","e","1","2","3",.........]
var = 0
answer = ""
while answer != password:
answer = idea[var]
print(answer)
var += 1
如果你重视你的眼睛,请不要向下看(警告你它很乱)。
<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>