Optimizing Brute Force Code for Python [closed]











up vote
-2
down vote

favorite












I need to do something for a science fair, and decided to find/modify/make a program to see how long it would take to "find" a password. After searching through the Internet, I found source code which I may use as inspiration to make my own program. However, I'm wondering if there was anything "wrong" or "slow" about this code. Also, I am failing to implement a system which can allow me to input the password that I wish to test (I'm an absolute beginner). So please, how can I make this code better, and how can I input a password to be cracked in the terminal? Sorry for any spelling mistakes, I'm not a native speaker.



Currently, to test for the password, I have to type in line 19 so the program knows if it is solved. As far as I can tell, this program uses the "Brute-Force" method in order to find a password. Also, just to be clear, this code is not originally mine. I believe this program is encoded with Python 2.



    import time
import string

maxattempts = 10000000000000000000
start = time.time()
chars = list(string.printable)[:95]
base = len(chars)
n = 0
solved = False
password = "ab" # This is where I put have to input the password.


print chars

# converts number N base 10 to a list of digits base b
def numberToBase(n, b):
digits =
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]


# begin systematically checking passwords
if not solved:
while n < maxattempts:
lst = numberToBase(n, base)
print(lst)
word = ''
for x in lst:
word += str(chars[x])
print(word)
if password == word:
solved = True
print('-Stats-')
print('Pass: ' + word)
print('Attempts: ' + str(n))
print('time: ' + str((time.time() - start)) + ' sec')
break
else:
n += 1

# number of trys go over the attempt limit
if not solved:
print('Unsolved after ' + str(n) + ' attempts!')









share|improve this question













closed as off-topic by AJNeufeld, Jamal Nov 26 at 4:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – AJNeufeld, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.

















    up vote
    -2
    down vote

    favorite












    I need to do something for a science fair, and decided to find/modify/make a program to see how long it would take to "find" a password. After searching through the Internet, I found source code which I may use as inspiration to make my own program. However, I'm wondering if there was anything "wrong" or "slow" about this code. Also, I am failing to implement a system which can allow me to input the password that I wish to test (I'm an absolute beginner). So please, how can I make this code better, and how can I input a password to be cracked in the terminal? Sorry for any spelling mistakes, I'm not a native speaker.



    Currently, to test for the password, I have to type in line 19 so the program knows if it is solved. As far as I can tell, this program uses the "Brute-Force" method in order to find a password. Also, just to be clear, this code is not originally mine. I believe this program is encoded with Python 2.



        import time
    import string

    maxattempts = 10000000000000000000
    start = time.time()
    chars = list(string.printable)[:95]
    base = len(chars)
    n = 0
    solved = False
    password = "ab" # This is where I put have to input the password.


    print chars

    # converts number N base 10 to a list of digits base b
    def numberToBase(n, b):
    digits =
    while n:
    digits.append(int(n % b))
    n //= b
    return digits[::-1]


    # begin systematically checking passwords
    if not solved:
    while n < maxattempts:
    lst = numberToBase(n, base)
    print(lst)
    word = ''
    for x in lst:
    word += str(chars[x])
    print(word)
    if password == word:
    solved = True
    print('-Stats-')
    print('Pass: ' + word)
    print('Attempts: ' + str(n))
    print('time: ' + str((time.time() - start)) + ' sec')
    break
    else:
    n += 1

    # number of trys go over the attempt limit
    if not solved:
    print('Unsolved after ' + str(n) + ' attempts!')









    share|improve this question













    closed as off-topic by AJNeufeld, Jamal Nov 26 at 4:18


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – AJNeufeld, Jamal

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I need to do something for a science fair, and decided to find/modify/make a program to see how long it would take to "find" a password. After searching through the Internet, I found source code which I may use as inspiration to make my own program. However, I'm wondering if there was anything "wrong" or "slow" about this code. Also, I am failing to implement a system which can allow me to input the password that I wish to test (I'm an absolute beginner). So please, how can I make this code better, and how can I input a password to be cracked in the terminal? Sorry for any spelling mistakes, I'm not a native speaker.



      Currently, to test for the password, I have to type in line 19 so the program knows if it is solved. As far as I can tell, this program uses the "Brute-Force" method in order to find a password. Also, just to be clear, this code is not originally mine. I believe this program is encoded with Python 2.



          import time
      import string

      maxattempts = 10000000000000000000
      start = time.time()
      chars = list(string.printable)[:95]
      base = len(chars)
      n = 0
      solved = False
      password = "ab" # This is where I put have to input the password.


      print chars

      # converts number N base 10 to a list of digits base b
      def numberToBase(n, b):
      digits =
      while n:
      digits.append(int(n % b))
      n //= b
      return digits[::-1]


      # begin systematically checking passwords
      if not solved:
      while n < maxattempts:
      lst = numberToBase(n, base)
      print(lst)
      word = ''
      for x in lst:
      word += str(chars[x])
      print(word)
      if password == word:
      solved = True
      print('-Stats-')
      print('Pass: ' + word)
      print('Attempts: ' + str(n))
      print('time: ' + str((time.time() - start)) + ' sec')
      break
      else:
      n += 1

      # number of trys go over the attempt limit
      if not solved:
      print('Unsolved after ' + str(n) + ' attempts!')









      share|improve this question













      I need to do something for a science fair, and decided to find/modify/make a program to see how long it would take to "find" a password. After searching through the Internet, I found source code which I may use as inspiration to make my own program. However, I'm wondering if there was anything "wrong" or "slow" about this code. Also, I am failing to implement a system which can allow me to input the password that I wish to test (I'm an absolute beginner). So please, how can I make this code better, and how can I input a password to be cracked in the terminal? Sorry for any spelling mistakes, I'm not a native speaker.



      Currently, to test for the password, I have to type in line 19 so the program knows if it is solved. As far as I can tell, this program uses the "Brute-Force" method in order to find a password. Also, just to be clear, this code is not originally mine. I believe this program is encoded with Python 2.



          import time
      import string

      maxattempts = 10000000000000000000
      start = time.time()
      chars = list(string.printable)[:95]
      base = len(chars)
      n = 0
      solved = False
      password = "ab" # This is where I put have to input the password.


      print chars

      # converts number N base 10 to a list of digits base b
      def numberToBase(n, b):
      digits =
      while n:
      digits.append(int(n % b))
      n //= b
      return digits[::-1]


      # begin systematically checking passwords
      if not solved:
      while n < maxattempts:
      lst = numberToBase(n, base)
      print(lst)
      word = ''
      for x in lst:
      word += str(chars[x])
      print(word)
      if password == word:
      solved = True
      print('-Stats-')
      print('Pass: ' + word)
      print('Attempts: ' + str(n))
      print('time: ' + str((time.time() - start)) + ' sec')
      break
      else:
      n += 1

      # number of trys go over the attempt limit
      if not solved:
      print('Unsolved after ' + str(n) + ' attempts!')






      python






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 at 2:31









      Allim

      11




      11




      closed as off-topic by AJNeufeld, Jamal Nov 26 at 4:18


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – AJNeufeld, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by AJNeufeld, Jamal Nov 26 at 4:18


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – AJNeufeld, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.



























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар