-
Notifications
You must be signed in to change notification settings - Fork 5
/
genter.py
698 lines (546 loc) · 22.6 KB
/
genter.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
#v4.0.1
#Imports
import beaupy
import hashlib
import json
import os
import sys
import wget
from string import ascii_lowercase, ascii_uppercase
from pystyle import Colors, Colorate
from alive_progress import alive_bar
from libs import rnd, kdf
import requests
#Languages
uppercase_letters = ascii_uppercase
lowercase_letters = ascii_lowercase
symbols = "!=<>'@#$%^&*()[\\],.;:-_/+?{|}`~"
unicode = "¡¢£¤¥¦§¨©ª«¬®™️¯°±²³´µ¶·¸¹º»¼½¾¿×Ø÷øÞ߃ðÐıæᔕ€≡‗"
emojis = "⚔☣️⚛️〰️🗝️🔒⛓️✨🫠🫧🫥💢🪬"
uni_boxes = "░▒▓█▄▀■"
uni_pipes = "╣╗╝┴┬╩╦═╬"
numbers = "012345678901234567890"
korean = "ㅂㅋㅎㅭㅱㅶㅹㅺㅿㆁㆄㆅ"
russian = "БГДЁЖИЙЛПФфЦЧШЩЪЫЬЭЮЯ"
chinese = "诶比西迪伊尺杰大水开勒哦屁吉吾儿诶比西迪伊弗吉尺艾弗吉杰屁吉吾儿八九十开勒马娜哦月人马娜口"
greek = "ΓΔΘΛΞΠΣΦΨΩαβγδεζηθικλμνξπρστυφχψω"
portu = "ãáàâçéêíõóôúüÃÁÀÂÇÉÊÍÕÓÔÚÜ"
hindi = "ऄअआइईउऊऋऌऍऎएऐऑऒओऔकखगघङचछजझञटठडढणतथदधनऩपफबभमयरऱलळऴवशषसहऽॐॠॡ।॥०१२३४५६७८९॰ॲॳॴॵॶॷॹॺॻॼॽॾॿೱೲऀँंःऺऻ़ािीुूृॄॅॆेैॉॊोौ्ॎॏ॒॑॓॔ॕॖॗॢॣ"
arabic = "شسژزڑرذڈدخحچجثٹتپبآاےیھہوںنملگکقفغعظطضصءئؤڙڐٿ٘ ًَُِّٰٗ؟،۰۱۲۳۴۵۶۷۸۹"
amharic = "ሀሁሂሃሄህሆሎልሌላሊሉለሐሑሒሓሔሕሖሞምሜማሚሙመሠሡሢሣሤሥሦሮርሬራሪሩረሰሱሲሳሴስሶሾሽሼሻሺሹሸቀቁቂቃቄቅቆቦብቤባቢቡበቨቩቪቫቬቭቮቶትቴታቲቱተቸቹቺቻቼችቾኆኅኄኃኂኁኀነኑኒናኔንኖኞኝኜኛኚኙኘአኡኢኣኤእኦኮክኬካኪኩከኸኹኺኻኼኽኾዎውዌዋዊዉወዐዑዒዓዔዕዖዞዝዜዛዚዙዘዠዡዢዣዤዥዦዮይዬያዪዩየደዱዲዳዴድዶጆጅጄጃጂጁጀገጉጊጋጌግጎጦጥጤጣጢጡጠጨጩጪጫጬጭጮጶጵጴጳጲጱጰጸጹጺጻጼጽጾፆፅፄፃፂፁፀፈፉፊፋፌፍፎፖፕፔፓፒፑፐ፩፪፫፬፭፮፯፰፱፲፳፴፵፶፷፸፹፺፻፼፡።፣፤፥"
sinhala = "්රඤචදසමහඒරැඅුටොි්යවනකතගලපබංජඩඉ𐐘𐑀ඞඕ" #SUS
hieroglyphs = "𓀨𓁢𓂀𓂁𓂄𓂉𓃣𓄯𓉢𓊇𓊆𓊉𓊈𓊎𓊕𓊔𓊖𓊗𓋹𓋸𓏲𓌬𓋨"
#Example | new_list = "WHATEVER YOU WANT HERE" | This can be named whatever you can think of, doesn't have to be "new_list". It's just what I am using for this example.
#You can add more and make it even more complex. Just make sure to update the rest of the code below.
##-------------- Functions --------------##
def banner():
banner = """
██████╗ ███████╗███╗ ██╗████████╗███████╗██████╗
██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝██╔════╝██╔══██╗
██║ ███╗█████╗ ██╔██╗ ██║ ██║ █████╗ ██████╔╝
██║ ██║██╔══╝ ██║╚██╗██║ ██║ ██╔══╝ ██╔══██╗
╚██████╔╝███████╗██║ ╚████║ ██║ ███████╗██║ ██║
╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
Made by Ori#6338 | @therealOri_ | https://github.com/therealOri
"""
colored_banner = Colorate.Horizontal(Colors.purple_to_blue, banner, 1)
return colored_banner
def clear():
os.system('cls||clear')
def str_hash(password, salt):
print(f'Press "ctrl+c" to go back/quit.\n{"-"*60}\n')
hash_lst = ['Argon2id - (recommended)', 'PBkdf2', 'Scrypt']
hash_type = beaupy.select(hash_lst, cursor_style="#ffa533")
if not hash_type:
return None
if hash_lst[0] in hash_type:
clear()
password = bytes(password, 'utf-8')
try:
salt = bytes(salt, 'utf-8')
except:
salt = os.urandom(64)
result1 = kdf.argon_hash(password, salt)
return result1[0], result1[1], hash_type
if hash_lst[1] in hash_type:
clear()
password = bytes(password, 'utf-8')
try:
salt = bytes(salt, 'utf-8')
except:
salt = os.urandom(64)
result1 = kdf.pbkdf2_hash(password, salt)
return result1[0], result1[1], hash_type
if hash_lst[2] in hash_type:
clear()
password = bytes(password, 'utf-8')
try:
salt = bytes(salt, 'utf-8')
except:
salt = os.urandom(64)
result1 = kdf.scrypt_hash(password, salt)
return result1[0], result1[1], hash_type
# config.json file loading.
def j_load():
if os.path.isfile('config.json'):
with open('config.json') as f:
data = json.load(f)
options_flag = data['password_options_flag']
secure_prompts = data['secure_prompts']
wordlst = data['wordlst_update']
return options_flag, secure_prompts, wordlst
else:
input('config.json file not found, press "enter" to create default config and continue...')
json_config = {
"password_options_flag": True,
"secure_prompts": False,
"wordlst_update": False
}
with open('config.json', 'w') as jwf:
json.dump(json_config, jwf, ensure_ascii=False, indent=4)
clear()
with open('config.json') as f:
data = json.load(f)
options_flag = data['password_options_flag']
secure_prompts = data['secure_prompts']
wordlst = data['wordlst_update']
return options_flag, secure_prompts, wordlst
# Showing contents of pass.txt and clearing it.
def show_pass():
with open('pass.txt', 'r', encoding = 'utf-8') as f:
result = f.read()
if not result:
return None
else:
return result
def clr_pass():
if os.path.getsize('pass.txt') > 0:
with open('pass.txt', 'r+') as f:
f.truncate(0)
return 200
else:
return 404
def update_words():
github_url = "https://raw.githubusercontent.com/therealOri/Genter/main/words.txt"
hash_url = "https://raw.githubusercontent.com/therealOri/Genter/main/words_hash.txt"
local_file = "words.txt"
response = requests.get(hash_url)
remote_hash = response.content.decode().strip()
with open(local_file, "rb") as f:
local_hash = hashlib.sha256(f.read()).hexdigest()
if remote_hash == local_hash:
clear()
print(f"Note: {local_file} is up-to-date.")
return
else:
clear()
print(f"Note: There is an update for {local_file}. Updating words...")
response = requests.get(github_url)
if response.status_code == 200:
with open(local_file, "wb") as f:
f.write(response.content)
input(f'{local_file} has been successfully updated!\n\nPress "enter" to continue...')
clear()
return 200
else:
clear()
input(f'Error: could not get {local_file} contents from GitHub. Please contact therealOri:https://github.com/therealOri/ on github if this continues...\n\nPress "enter" to continue..."')
clear()
return 404
#Generate Phrases (Like Bitwarden)
def phrzgn():
clear()
dash=60
if os.path.isfile('words.txt'):
if j_load()[2]:
check = update_words()
if check == 404:
return
else:
pass #updates set to false. Continue.
else:
clear()
print("words.txt doesn't exist and is to big to create...Downloading words.txt from repo.")
wget.download("https://raw.githubusercontent.com/therealOri/Genter/main/words.txt")
clear()
while True:
try:
clear()
print(banner())
number = beaupy.prompt(f'(Press "ctrl+c" to exit)\n{"-"*dash}\n\nHow many words?: ')
if number is None:
clear()
return
else:
number = int(number)
except ValueError as e:
clear()
print(f'Oops! Something went wrong.\nError: {e}\n\n')
input('Press "enter" to continue...')
clear()
continue
if number > 20 or number < 3:
clear()
print("20 words is the maximum number of words you can use. And 5 words is the minimum.\n\n")
input('Press "enter" to continue...')
clear()
else:
break
cwd = os.getcwd()
word_path = f"{cwd}/words.txt"
with open(word_path, 'r') as fh:
words = fh.read().lower()
word_list = words.splitlines() #list of words
clear()
print(banner())
sep = beaupy.prompt(f'(Press "ctrl+c" to exit)\n{"-"*dash}\n\nLine separator? (leave empty for default "-"): ')
if sep is None:
clear()
return
else:
if sep == '':
sep = '-'
#Returns True or False. Basically Yes or No?
capital_words = ''
default_words = ''
clear()
print(banner())
capitalize = beaupy.confirm(f'(Press "ctrl+c" to exit)\n{"-"*dash}\n\nCapitalize?')
if capitalize is None:
clear()
return
else:
if capitalize:
"""Make list of words with the first letter capitalized."""
c_lst = []
for i in word_list:
if len(i) < 3 or len(i) > 9:
pass #Ignore and move on to next item
else:
c_lst.append(i.title())
cap = True
capital_words = f'{sep}'.join(rnd.choice(c_lst) for _ in range(number))
else:
cap = False
default_words = f'{sep}'.join(rnd.choice(word_list) for _ in range(number))
clear()
print(banner())
numbers = beaupy.confirm(f'(Press "ctrl+c" to exit)\n{"-"*dash}\n\nNumber?')
if numbers is None:
clear()
return
else:
if numbers:
num = True
rn_num = rnd.randint(0, 9) # <-- Get a random number to be used with only 1 of the words defined in capital_words or default_words below.
word_index = rnd.randint(0, number-1) # Get random index that is in the word list
if default_words != '':
word_with_number = default_words.split(sep)
else:
word_with_number = capital_words.split(sep)
word_with_number[word_index] = word_with_number[word_index] + str(rn_num)
word_with_number = sep.join(word_with_number)
else:
num = False
if num:
return word_with_number
elif cap:
return capital_words
else:
return default_words
def main():
try:
#You can configure what you want to do in the config.json file.
if j_load()[0]:
langs = ['uppercase', 'lowercase', 'numbers', 'symbols', 'korean', 'russian', 'chinese', 'greek', 'portu', 'unicode', 'uni_boxes', 'uni_pipes', 'hindi', 'arabic', 'emojis', 'amharic', 'sinhala', 'hieroglyphs']
# Choose multiple options from a list
clear()
print(banner())
print('\n\n\nChose your options! (If no options are selected you will be returned back to the main menu.)\nPress "CTRL+C" to exit this menu.\n\n')
langs_config = beaupy.select_multiple(langs, ticked_indices=[0,1,2,3], tick_style="#ed1dd3", cursor_style="#ffa533", tick_character="x")
all = ""
if langs[0] in langs_config:
all += uppercase_letters
if langs[1] in langs_config:
all += lowercase_letters
if langs[2] in langs_config:
all += numbers
if langs[3] in langs_config:
all += symbols
if langs[4] in langs_config:
all += korean
if langs[5] in langs_config:
all += russian
if langs[6] in langs_config:
all += chinese
if langs[7] in langs_config:
all += greek
if langs[8] in langs_config:
all += portu
if langs[9] in langs_config:
all += unicode
if langs[10] in langs_config:
all += uni_boxes
if langs[11] in langs_config:
all += uni_pipes
if langs[12] in langs_config:
all += hindi
if langs[13] in langs_config:
all += arabic
if langs[14] in langs_config:
all += emojis
if langs[15] in langs_config:
all += amharic
if langs[16] in langs_config:
all += sinhala
if langs[17] in langs_config:
all += hieroglyphs
if not langs_config:
clear()
return
else:
upper = True
lower = True
nums = True
syms = True
kor = True
rus = True
chi = True
grk = True
port = True
spec = True
block = True
pipes = True
hin = True
arab = True
emote = True
amha = True
sinha = True
hiero = True
all = ""
if upper:
all += uppercase_letters
if lower:
all += lowercase_letters
if nums:
all += numbers
if syms:
all += symbols
if kor:
all += korean
if rus:
all += russian
if chi:
all += chinese
if grk:
all += greek
if port:
all += portu
if spec:
all += unicode
if block:
all += uni_boxes
if pipes:
all += uni_pipes
if hin:
all += hindi
if arab:
all += arabic
if emote:
all += emojis
if amha:
all += amharic
if sinha:
all += sinhala
if hiero:
all += hieroglyphs
except Exception as e:
clear()
print(f"Oops! Something went wrong...\nERROR: {e}\n\n")
input('Press "enter" to continue...')
clear()
return
clear()
print(banner())
print('WARNING!!: Password(s) WILL be overwritten when generating passwords again.\nPress "q" or "ctrl+c" to go back. \n\n')
try:
length = beaupy.prompt('How long do you want your password(s)?: ')
if not length:
clear()
return None
elif length.lower() == 'q':
clear()
return None
else:
length = int(length)
except Exception as e:
clear()
print(f'Oops..The value you gave me is not a number/integer.\n[Error]: {e}')
input('\nPress "enter" to continue...')
return None
try:
clear()
print(banner())
amount = beaupy.prompt('How many do you want generated?: ')
if not amount:
clear()
return None
elif amount.lower() == 'q':
clear()
return None
else:
amount = int(amount)
except Exception as e:
clear()
print(f'Oops..The value you gave me is not a number/integer.\n[Error]: {e}')
input('\nPress "enter" to continue...')
return None
clear()
all_text = rnd.shuffle(all)
print(f"Army of hamsters deployed...generating password(s)...\n{'-'*100}")
with alive_bar(amount) as bar:
with open('pass.txt', 'w', encoding = 'utf-8') as wf:
c=0
for _ in range(amount):
c+=1
password = ''.join(rnd.choice(all_text) for _ in range(length))
password = rnd.shuffle(password)
print(f'Pass {c}: {password}', file=wf)
bar()
clear()
print(banner())
print('\n\n\nYour newly generated password(s) has been saved to "pass.txt".\n\n')
input('Press "enter" to continue...')
clear()
##-------------- ^^ Functions End ^^ --------------##
if __name__ == '__main__':
dash=60
while True:
clear()
#NOTE - This format will leave room for expansion of features.
#
# Passwords - (Make pass, Make phrase, Show pass, Clear pass)
# Get hash
# Exit
main_options = ['[1] - Passwords?', '[2] - Get Hashes', '[3] - Exit?']
print(f'{banner()}\n\nWhat would you like to do?\n{"-"*dash}\n')
main_option = beaupy.select(main_options, cursor_style="#ffa533")
if not main_option:
clear()
sys.exit("Keyboard Interruption Detected!\nGoodbye <3")
if main_options[0] in main_option:
while True:
clear()
password_options = ['[1] - Make Password?', '[2] - Make phrase?', '[3] - Show pass.txt', '[4] - Clear pass.txt', '[5] - Back?']
print(f'{banner()}\n\nWhat would you like to do?\n{"-"*dash}\n')
pass_option = beaupy.select(password_options, cursor_style="#ffa533")
if not pass_option:
clear()
break
if password_options[0] in pass_option:
"""Make Passwords"""
clear()
main()
if password_options[1] in pass_option:
"""Make Phrases"""
clear()
phrase = phrzgn()
if phrase is None:
clear()
else:
clear()
print(f'{banner()}\n{"-"*dash}\n\nPhrase: {phrase}')
input('\n\nPress "enter" to continue...')
clear()
if password_options[2] in pass_option:
"""Show pass.txt"""
if os.path.isfile('pass.txt'):
clear()
passwords = show_pass()
if not passwords:
print('No passwords found in "pass.txt"\n\n')
input('Press "enter" to continue...')
clear()
else:
print(passwords)
input('Press "enter" to continue...')
clear()
else:
clear()
with open('pass.txt', 'w') as fm:
fm.write('\n')
clr_pass()
input("pass.txt was not found and has been created successfully!.\n\nPress 'enter' to continue...")
clear()
continue
if password_options[3] in pass_option:
"""Clear pass.txt"""
if os.path.isfile('pass.txt'):
check = clr_pass()
clear()
print(banner())
if check == 200:
input('Success: pass.txt has been wiped clean.\n\nPress "enter" to continue...')
clear()
else:
input('Error: pass.txt file is already empty.\n\nPress "enter" to continue...')
clear()
else:
clear()
with open('pass.txt', 'w') as fm:
fm.write('\n')
clr_pass()
input("pass.txt was not found and has been created successfully!.\n\nPress 'enter' to continue...")
clear()
continue
if password_options[4] in pass_option:
clear()
break
#hashing
if main_options[1] in main_option:
clear()
if j_load()[1]:
clear()
print(banner())
pword = beaupy.prompt(f'Press "q" to go back/quit.\n{"-"*dash}\nWhat would you like to hash?: ', secure=True)
if not pword or pword.lower() == 'q':
clear()
continue
clear()
print(banner())
salt = beaupy.prompt(f'Press "q" to go back/quit.\n{"-"*dash}\nWhat would you like to have as the salt?', secure=True)
if not salt or salt.lower() == 'q':
clear()
continue
else:
clear()
print(banner())
pword = beaupy.prompt(f'Press "q" to go back/quit.\n{"-"*dash}\nWhat would you like to hash?: ', secure=False)
if not pword or pword.lower() == 'q':
clear()
continue
clear()
print(banner())
salt = beaupy.prompt(f'Press "q" to go back/quit.\n{"-"*dash}\nWhat would you like to have as the salt?', secure=False)
if not salt or salt.lower() == 'q':
clear()
continue
clear()
print(banner())
final_hash = str_hash(pword, salt)
if not final_hash:
clear()
continue
# "final_hash[2]" is name of hash that was used. "[1]" is the salt and "[0]" is the actual hash value.
if len(final_hash[2]) > 6:
final_hash_o = final_hash[2][0:-16]
else:
final_hash_o = final_hash[2]
clear()
print(banner())
print(f'\n\n\nSelected Option: {final_hash_o}\n{"-"*dash}\nMessage: "{pword}"\nDerived Hash: {final_hash[0]}\nSalt - {final_hash[1]}\n\n')
input('Press "enter" to continue...')
clear()
if main_options[2] in main_option:
clear()
sys.exit("Goodbye! <3")