我是一个编写代码的初学者,我已经开始使用Python,因为它似乎是最整洁和最容易入门的(我目前使用的是Python3.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的知识。
发布于 2012-07-07 02:40:46
代码优先:
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的灵活性和可用的工具有一个概念。
我将让您检查密码是否匹配,然后中断循环。
发布于 2012-07-07 02:17:08
你想要这样的东西:
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)
发布于 2019-03-11 00:25:39
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"))
https://stackoverflow.com/questions/11367553
复制相似问题