Make password/hash verification algorithm more efficient












0















I am trying to guess the paswords from the etc/shadow file(it has 43 user/passwords). And I have been given some hints about the passwords:




  • Length is between 4 and 8 characters

  • There can be only 2 numbers and only at the end

  • Capital letters only in the beginning


So I started just with a small group composed by 4 character with 2 digits in it. But it takes so much time to process:



import crypt
import string
import itertools
import datetime

dir = "shadow3"
file = open(dir, 'r').readlines() #Read all the 43 hashes

username =
hashed =
c = 0
cc = 0

for x in file: #Split the hash and the username
usr, hshd, wtf, iss, this, thing, here, doing, example = x.split(':')
username.append(usr)
hashed.append(hshd)
#GRUPO1 4 caracteres 2 numeros
letters = string.ascii_lowercase
digits = string.digits
grupo1=
group1=itertools.product(letters,repeat=2)
group1b=itertools.product(digits,repeat=2)
for x in itertools.product(group1,group1b): #Join the possible iterations
string=''.join([''.join(k) for k in x])
grupo1.append(string)
print(len(grupo1))
for y in grupo1:#Get the one of the iterations and try it
prueba=y
for x in hashed: #Verify if that iteration is the password to any of the 43 users
rehashed = crypt.crypt(prueba, x)
if rehashed == x: #Password is found
print('La contraseña del usuario ' + username[c] + ' es ' + prueba)
cc = 1
c = c + 1
if cc == 0: #after all iterations password is not found
print('Lo sentimos "' + prueba + '" no es la contraseña de ningun usuario')


How can I improve the efficiency of this? I have a GTX 1070 if it helps for any kind of GPU processing.










share|improve this question




















  • 1





    If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

    – usr2564301
    Nov 23 '18 at 16:24
















0















I am trying to guess the paswords from the etc/shadow file(it has 43 user/passwords). And I have been given some hints about the passwords:




  • Length is between 4 and 8 characters

  • There can be only 2 numbers and only at the end

  • Capital letters only in the beginning


So I started just with a small group composed by 4 character with 2 digits in it. But it takes so much time to process:



import crypt
import string
import itertools
import datetime

dir = "shadow3"
file = open(dir, 'r').readlines() #Read all the 43 hashes

username =
hashed =
c = 0
cc = 0

for x in file: #Split the hash and the username
usr, hshd, wtf, iss, this, thing, here, doing, example = x.split(':')
username.append(usr)
hashed.append(hshd)
#GRUPO1 4 caracteres 2 numeros
letters = string.ascii_lowercase
digits = string.digits
grupo1=
group1=itertools.product(letters,repeat=2)
group1b=itertools.product(digits,repeat=2)
for x in itertools.product(group1,group1b): #Join the possible iterations
string=''.join([''.join(k) for k in x])
grupo1.append(string)
print(len(grupo1))
for y in grupo1:#Get the one of the iterations and try it
prueba=y
for x in hashed: #Verify if that iteration is the password to any of the 43 users
rehashed = crypt.crypt(prueba, x)
if rehashed == x: #Password is found
print('La contraseña del usuario ' + username[c] + ' es ' + prueba)
cc = 1
c = c + 1
if cc == 0: #after all iterations password is not found
print('Lo sentimos "' + prueba + '" no es la contraseña de ningun usuario')


How can I improve the efficiency of this? I have a GTX 1070 if it helps for any kind of GPU processing.










share|improve this question




















  • 1





    If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

    – usr2564301
    Nov 23 '18 at 16:24














0












0








0








I am trying to guess the paswords from the etc/shadow file(it has 43 user/passwords). And I have been given some hints about the passwords:




  • Length is between 4 and 8 characters

  • There can be only 2 numbers and only at the end

  • Capital letters only in the beginning


So I started just with a small group composed by 4 character with 2 digits in it. But it takes so much time to process:



import crypt
import string
import itertools
import datetime

dir = "shadow3"
file = open(dir, 'r').readlines() #Read all the 43 hashes

username =
hashed =
c = 0
cc = 0

for x in file: #Split the hash and the username
usr, hshd, wtf, iss, this, thing, here, doing, example = x.split(':')
username.append(usr)
hashed.append(hshd)
#GRUPO1 4 caracteres 2 numeros
letters = string.ascii_lowercase
digits = string.digits
grupo1=
group1=itertools.product(letters,repeat=2)
group1b=itertools.product(digits,repeat=2)
for x in itertools.product(group1,group1b): #Join the possible iterations
string=''.join([''.join(k) for k in x])
grupo1.append(string)
print(len(grupo1))
for y in grupo1:#Get the one of the iterations and try it
prueba=y
for x in hashed: #Verify if that iteration is the password to any of the 43 users
rehashed = crypt.crypt(prueba, x)
if rehashed == x: #Password is found
print('La contraseña del usuario ' + username[c] + ' es ' + prueba)
cc = 1
c = c + 1
if cc == 0: #after all iterations password is not found
print('Lo sentimos "' + prueba + '" no es la contraseña de ningun usuario')


How can I improve the efficiency of this? I have a GTX 1070 if it helps for any kind of GPU processing.










share|improve this question
















I am trying to guess the paswords from the etc/shadow file(it has 43 user/passwords). And I have been given some hints about the passwords:




  • Length is between 4 and 8 characters

  • There can be only 2 numbers and only at the end

  • Capital letters only in the beginning


So I started just with a small group composed by 4 character with 2 digits in it. But it takes so much time to process:



import crypt
import string
import itertools
import datetime

dir = "shadow3"
file = open(dir, 'r').readlines() #Read all the 43 hashes

username =
hashed =
c = 0
cc = 0

for x in file: #Split the hash and the username
usr, hshd, wtf, iss, this, thing, here, doing, example = x.split(':')
username.append(usr)
hashed.append(hshd)
#GRUPO1 4 caracteres 2 numeros
letters = string.ascii_lowercase
digits = string.digits
grupo1=
group1=itertools.product(letters,repeat=2)
group1b=itertools.product(digits,repeat=2)
for x in itertools.product(group1,group1b): #Join the possible iterations
string=''.join([''.join(k) for k in x])
grupo1.append(string)
print(len(grupo1))
for y in grupo1:#Get the one of the iterations and try it
prueba=y
for x in hashed: #Verify if that iteration is the password to any of the 43 users
rehashed = crypt.crypt(prueba, x)
if rehashed == x: #Password is found
print('La contraseña del usuario ' + username[c] + ' es ' + prueba)
cc = 1
c = c + 1
if cc == 0: #after all iterations password is not found
print('Lo sentimos "' + prueba + '" no es la contraseña de ningun usuario')


How can I improve the efficiency of this? I have a GTX 1070 if it helps for any kind of GPU processing.







python hash coding-efficiency






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 0:29









James K Polk

30.2k116896




30.2k116896










asked Nov 23 '18 at 14:33









19mike9519mike95

5518




5518








  • 1





    If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

    – usr2564301
    Nov 23 '18 at 16:24














  • 1





    If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

    – usr2564301
    Nov 23 '18 at 16:24








1




1





If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

– usr2564301
Nov 23 '18 at 16:24





If your code works without errors, Code Review might be a better place to ask on. Stack Overflow soecializes in not-working code.

– usr2564301
Nov 23 '18 at 16:24












2 Answers
2






active

oldest

votes


















1














I believe your code has errors. Your problem could be re-modelled so that it could be faster:



Generate all combination of possible passwords, based on your criteria
- Length is between 4 and 8 characters
- There can be only 2 numbers and only at the end
- Capital letters only in the beginning



Generate crypt() on each of the combinations
Compare passwords vs the crypted values.






share|improve this answer































    0














    Luckily, Python comes with a profiler to help solve this kind of problem. Look at the cProfile documentation.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448580%2fmake-password-hash-verification-algorithm-more-efficient%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I believe your code has errors. Your problem could be re-modelled so that it could be faster:



      Generate all combination of possible passwords, based on your criteria
      - Length is between 4 and 8 characters
      - There can be only 2 numbers and only at the end
      - Capital letters only in the beginning



      Generate crypt() on each of the combinations
      Compare passwords vs the crypted values.






      share|improve this answer




























        1














        I believe your code has errors. Your problem could be re-modelled so that it could be faster:



        Generate all combination of possible passwords, based on your criteria
        - Length is between 4 and 8 characters
        - There can be only 2 numbers and only at the end
        - Capital letters only in the beginning



        Generate crypt() on each of the combinations
        Compare passwords vs the crypted values.






        share|improve this answer


























          1












          1








          1







          I believe your code has errors. Your problem could be re-modelled so that it could be faster:



          Generate all combination of possible passwords, based on your criteria
          - Length is between 4 and 8 characters
          - There can be only 2 numbers and only at the end
          - Capital letters only in the beginning



          Generate crypt() on each of the combinations
          Compare passwords vs the crypted values.






          share|improve this answer













          I believe your code has errors. Your problem could be re-modelled so that it could be faster:



          Generate all combination of possible passwords, based on your criteria
          - Length is between 4 and 8 characters
          - There can be only 2 numbers and only at the end
          - Capital letters only in the beginning



          Generate crypt() on each of the combinations
          Compare passwords vs the crypted values.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 16:36









          yoonghmyoonghm

          1,106918




          1,106918

























              0














              Luckily, Python comes with a profiler to help solve this kind of problem. Look at the cProfile documentation.






              share|improve this answer




























                0














                Luckily, Python comes with a profiler to help solve this kind of problem. Look at the cProfile documentation.






                share|improve this answer


























                  0












                  0








                  0







                  Luckily, Python comes with a profiler to help solve this kind of problem. Look at the cProfile documentation.






                  share|improve this answer













                  Luckily, Python comes with a profiler to help solve this kind of problem. Look at the cProfile documentation.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 15:02









                  musburmusbur

                  947




                  947






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448580%2fmake-password-hash-verification-algorithm-more-efficient%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin