Violent Python Chapter #1 Part 2

I’ve finished the second exercise from Violent Python’s Chapter #1 “The cuckoo’s egg”, it is a password decrypter. Here’s the code:

    #
    # Violent Python Chapter #1
    # The Cuckoo's Egg: a simple password decrypter
    # By: Marin Alcaraz
    #
    
    import crypt
    import hashlib
    
    def testPass(cryptPass):
        salt = cryptPass[0:2]
        dictFile = open('dictionary.txt', 'r')
        for word in dictFile.readlines():
            word = word.strip('\n')
            cryptWord = crypt.crypt(word, salt)
            if (cryptWord == cryptPass or hashlib.sha512(word) == cryptPass):
                print "[+] Found Password: " + word + "\n"
                return
        print "[-] Password not found.\n"
        return
    
    def main():
        passFile = open("passwords.txt", 'r')
        for line in passFile.readlines():
            if ":" in line:
                user = line.split(':')[0]
                cryptPass = line.split(':')[1].strip(' ')
                print "[*] Cracking Password for: user[" + user + "]\n"
                testPass(cryptPass)
        return
    
    if __name__ == "__main__":
        main()

Leave a comment

Leave a Reply