Skip to content

Commit d128444

Browse files
Create Password_guess.py
Created Password guessing game
1 parent e9e7c96 commit d128444

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

other/Password_guess.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import random
2+
import os
3+
4+
# Define the list of possible characters
5+
pwd = ['a', 'b', 'c', 'd', 'e', 'f', '1', '2', '3', '4', '5', '6',
6+
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
7+
's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
8+
9+
# Input from the user
10+
u_pwd = input("Enter a password: ")
11+
12+
# Initialize an empty string to store the guessed password
13+
pw = ""
14+
15+
while pw != u_pwd:
16+
# Reset the guessed password to an empty string
17+
pw = ""
18+
19+
# Generate a guess by selecting random characters from the pwd list
20+
for _ in range(len(u_pwd)):
21+
guess_pwd = random.choice(pwd)
22+
pw += guess_pwd
23+
24+
# Print progress information
25+
print(f"Attempting to crack password: {pw}")
26+
27+
# Clear the console for the next attempt
28+
os.system("cls" if os.name == 'nt' else "clear")
29+
30+
# Output the result once the password is found
31+
print(f"Your password is: {pw}")

0 commit comments

Comments
 (0)