Python Password Cracker
Question:
My code is
from random import *
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
My goal is to get it to randomly generate letters and stick them together to make the length of the password, and do this until it finds the password. Every time I run it, it just makes the command prompt look like something from the Matrix. Is there something I’m doing wrong?
P.S. I’m doing this to see how hard it would be to crack a password. I have no intent of hacking into other people’s accounts.
Answers:
You never reset “guess” so it just keeps getting bigger and bigger.
from random import *
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
As it was already said, you are not properly reseting your guess.
Also, that`s not how you crack passwords, since you are repeating the same guesses over and over. You need to somehow go over all the possibilities, without repeating yourself.
Say your password is 4 letters long, you can start with aaaa, then aaab, until zzzz. You may do it in another order, a random one, but you should test each case only once.
I have modified the code a bit to include itertools.permutations(guess)
to get all the possible combination of that random guess and test against it. This will save some time.
from random import *
import itertools
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
perm = ""
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
perm = itertools.permutations(guess)
for p in perm:
guess = "".join(p)
print(" ",guess,end="r")
print(f"Password guessed! ==> {guess}")
input("")
-
pasword generator using python in 30 secand
2
3 import random
4 lowar_case="abcdefbhijklmnopqrstuvwxyz
5 upper_ case="ABCDEFGHIJKLMNOPQRSTUVWXYZ
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
for letter in password:
guess letter = letters[rand ant(0, 25)]
guess = sir(guess letter) + sir(guess)
print(guess)
print("Password guessed!")
input("")
My code is
from random import *
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
My goal is to get it to randomly generate letters and stick them together to make the length of the password, and do this until it finds the password. Every time I run it, it just makes the command prompt look like something from the Matrix. Is there something I’m doing wrong?
P.S. I’m doing this to see how hard it would be to crack a password. I have no intent of hacking into other people’s accounts.
You never reset “guess” so it just keeps getting bigger and bigger.
from random import *
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
As it was already said, you are not properly reseting your guess.
Also, that`s not how you crack passwords, since you are repeating the same guesses over and over. You need to somehow go over all the possibilities, without repeating yourself.
Say your password is 4 letters long, you can start with aaaa, then aaab, until zzzz. You may do it in another order, a random one, but you should test each case only once.
I have modified the code a bit to include itertools.permutations(guess)
to get all the possible combination of that random guess and test against it. This will save some time.
from random import *
import itertools
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
perm = ""
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
perm = itertools.permutations(guess)
for p in perm:
guess = "".join(p)
print(" ",guess,end="r")
print(f"Password guessed! ==> {guess}")
input("")
-
pasword generator using python in 30 secand
2
3 import random
4 lowar_case="abcdefbhijklmnopqrstuvwxyz
5 upper_ case="ABCDEFGHIJKLMNOPQRSTUVWXYZ
guess = ""
password = input("Password: ")
letters = ["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"]
while (guess != password):
guess = ""
for letter in password:
guess letter = letters[rand ant(0, 25)]
guess = sir(guess letter) + sir(guess)
print(guess)
print("Password guessed!")
input("")