Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 624647b

Browse files
author
ravishhankar
committed
Merged with master branch
1 parent a58b8d6 commit 624647b

File tree

6 files changed

+176976
-0
lines changed

6 files changed

+176976
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import random
2+
import math
3+
alpha = "abcdefghijklmnopqrstuvwxyz"
4+
num = "0123456789"
5+
special = "@#$%&*"
6+
7+
# pass_len=random.randint(8,13) #without User INput
8+
pass_len = int(input("Enter Password Length"))
9+
10+
# length of password by 50-30-20 formula
11+
alpha_len = pass_len//2
12+
num_len = math.ceil(pass_len*30/100)
13+
special_len = pass_len-(alpha_len+num_len)
14+
15+
16+
password = []
17+
18+
19+
def generate_pass(length, array, is_alpha=False):
20+
for i in range(length):
21+
index = random.randint(0, len(array) - 1)
22+
character = array[index]
23+
if is_alpha:
24+
case = random.randint(0, 1)
25+
if case == 1:
26+
character = character.upper()
27+
password.append(character)
28+
29+
30+
# alpha password
31+
generate_pass(alpha_len, alpha, True)
32+
# numeric password
33+
generate_pass(num_len, num)
34+
# special Character password
35+
generate_pass(special_len, special)
36+
# suffle the generated password list
37+
random.shuffle(password)
38+
# convert List To string
39+
gen_password = ""
40+
for i in password:
41+
gen_password = gen_password + str(i)
42+
print(gen_password)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
import random
3+
4+
# check if filename is supplied as a command line argument
5+
if sys.argv[1:]:
6+
filename = sys.argv[1]
7+
else:
8+
filename = input("What is the name of the file? (extension included): ")
9+
10+
try:
11+
file = open(filename)
12+
except (FileNotFoundError, IOError):
13+
print("File doesn't exist!")
14+
exit()
15+
# handle exception
16+
17+
# get number of lines
18+
num_lines = sum(1 for line in file if line.rstrip())
19+
20+
# generate a random number between possible interval
21+
random_line = random.randint(0, num_lines)
22+
23+
# re-iterate from first line
24+
file.seek(0)
25+
26+
for i, line in enumerate(file):
27+
if i == random_line:
28+
print(line.rstrip()) # rstrip removes any trailing newlines :)
29+
break

0 commit comments

Comments
 (0)