-
Notifications
You must be signed in to change notification settings - Fork 1
/
random-char-gen.py
154 lines (138 loc) · 4.98 KB
/
random-char-gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Date: 12/19/2020
# Author: Enes
# Description: Random Character / String Generator
import os
import csv
import sys
import string
import random
from colorama import Fore, init
os.system("cls")
init()
def main():
menu()
def menu():
print(f"""{Fore.CYAN}
╔═╗┬ ┬┌─┐┬─┐ ╔═╗┌─┐┌┐┌
║ ├─┤├─┤├┬┘ ║ ╦├┤ │││
╚═╝┴ ┴┴ ┴┴└─ ╚═╝└─┘┘└┘{Fore.RESET}""")
choice = input(f"""
{Fore.LIGHTYELLOW_EX}[1]{Fore.RESET} Custom Letters
{Fore.LIGHTYELLOW_EX}[2]{Fore.RESET} Strong Password/s
{Fore.LIGHTYELLOW_EX}[3]{Fore.RESET} Letters and Numbers
{Fore.LIGHTYELLOW_EX}[4]{Fore.RESET} Without repeating Characters
{Fore.LIGHTYELLOW_EX}[5]{Fore.RESET} Lower-Case and Upper-Case Letters
{Fore.LIGHTYELLOW_EX}[6]{Fore.RESET} Exit
What do you want to do? \n» """)
print()
if choice == "1":
custom()
elif choice == "2":
strongpw()
elif choice == "3":
letnum()
elif choice == "4":
norep()
elif choice == "5":
uplow()
elif choice == "6":
sys.exit
else:
print("Select a valid option.. \n Please repeat.")
menu()
def custom():
sample_letters = input('Which Letters / Numbers should the Characters contain? \n» ')
print()
length = int(input("How many Characters in one? \n» "))
print()
number = int(input("How many do you want to generate? \n» "))
print()
for i in range(number):
result_str = ''.join((random.choice(sample_letters) for i in range(length)))
print(result_str)
with open('custom.txt', "a") as x:
x.write(f"{result_str}\n")
yesno = input("\nDo you want to save them into an Text File? \n» ")
if str(yesno).startswith("n" or "N"):
os.remove("custom.txt")
print("\nDone without Saving! Press Enter to Exit.")
input()
else:
print("\nDone! Press Enter to Exit.")
input()
def strongpw():
password_characters = string.ascii_letters + string.digits + string.punctuation
length = int(input("How many Characters in one? \n» "))
print()
number = int(input("How many do you want to generate? \n» "))
print()
for i in range(number):
password = ''.join(random.choice(password_characters) for i in range(length))
print(password)
with open('passwords.txt', "a") as x:
x.write(f"{password}\n")
yesno = input("\nDo you want to save them into an Text File? \n» ")
if str(yesno).startswith("n" or "N"):
os.remove("passwords.txt")
print("\nDone without Saving! Press Enter to Exit.")
input()
else:
print("\nDone! Press Enter to Exit.")
input()
def letnum():
letters_and_digits = string.ascii_letters + string.digits
length = int(input("How many Characters in one? \n» "))
print()
number = int(input("How many do you want to generate? \n» "))
print()
for i in range(number):
result_str = ''.join((random.choice(letters_and_digits) for i in range(length)))
print(result_str)
with open('lettersnumbers.txt', "a") as x:
x.write(f"{result_str}\n")
yesno = input("\nDo you want to save them into an Text File? \n» ")
if str(yesno).startswith("n" or "N"):
os.remove("lettersnumbers.txt")
print("\nDone without Saving! Press Enter to Exit.")
input()
else:
print("\nDone! Press Enter to Exit.")
input()
def norep():
letters = string.ascii_lowercase
length = int(input("How many Characters in one? \n» "))
print()
number = int(input("How many do you want to generate? \n» "))
print()
for i in range(number):
result_str = ''.join(random.sample(letters, length))
print(result_str)
with open('norepeat.txt', "a") as x:
x.write(f"{result_str}\n")
yesno = input("\nDo you want to save them into an Text File? \n» ")
if str(yesno).startswith("n" or "N"):
os.remove("norepeat.txt")
print("\nDone without Saving! Press Enter to Exit.")
input()
else:
print("\nDone! Press Enter to Exit.")
input()
def uplow():
length = int(input("How many Characters in one? \n» "))
print()
number = int(input("How many do you want to generate? \n» "))
letters = string.ascii_letters
for i in range(number):
result_str = ''.join(random.choice(letters) for i in range(length))
print(result_str)
with open('chars.txt', "a") as x:
x.write(f"{result_str}\n")
yesno = input("\nDo you want to save them into an Text File? \n» ")
if str(yesno).startswith("n" or "N"):
os.remove("chars.txt")
print("\nDone without Saving! Press Enter to Exit.")
input()
else:
print("\nDone! Press Enter to Exit.")
input()
main()