Some guru help me with the decrypting tool Python 3 code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Some guru help me with the decrypting tool Python 3 code

I have written a simple password generator (MODULE 1) and wanted to add a decrypting tool(MODULE 2). MODULE 1 works just fine (feel free to point out and possible optimizing, though), I have trouble with MODULE 2, I cannot locate the bug. # PROJECT 9 ENCRYPTOR and DECRYPTOR # MODULE 1: password generator from random import randint while True: try: digit = int(input('please enter the digit of numberic password= ')) except: print('please enter numberic input') pw = '0' i = 2 while i <= digit: pw_tmp = randint(0, 9) i += 1 pw = pw + str(pw_tmp) print(pw) # MODULE 2: password cracker pw = '012345' digit = len(pw) pw_crack = '0' p = 0 count = 0 while p <= digit - 1: q = 0 while q <= 9: count += 1 if str(q) == pw[p]: pw_crack = pw_crack + str(q) continue else: q += 1 p += 1 print(pw_crack) print(count)

15th Dec 2016, 4:02 PM
Ethan ZHOU
Ethan ZHOU - avatar
2 Answers
+ 3
pw = '012345' digit = len(pw) pw_crack = '' #no need for an extra 0 p = 0 count = 0 while p <= digit - 1: q = 0 while q <= 9: count += 1 if str(q) == pw[p]: pw_crack = pw_crack + str(q) break """continue would run loop all the time.""" else: q += 1 p += 1 print(pw_crack) print(count)
16th Dec 2016, 4:59 AM
nitesh
0
thanks a lot. esp for the continue and break thing, and I'm glad to learn there can be an empty string ".
16th Dec 2016, 5:03 AM
Ethan ZHOU
Ethan ZHOU - avatar