Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'position,': 0.05; 'subject:Python': 0.06; 'method.': 0.07; 'sys': 0.07; 'string': 0.09; '#print': 0.09; 'width': 0.09; 'def': 0.12; '1):': 0.16; 'basestring):': 0.16; 'characters:': 0.16; 'dictionary.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'improper': 0.16; 'md5': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'missing?': 0.16; 'skips': 0.16; 'string:': 0.16; 'sys.exit(1)': 0.16; 'two.': 0.16; 'skip:= 10': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'input': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'char': 0.24; "i've": 0.25; 'shown': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'characters': 0.30; 'code': 0.31; '"")': 0.31; 'apparently': 0.31; 'post.': 0.31; 'anyone': 0.31; 'skip:c 30': 0.32; 'checking': 0.33; 'subject:with': 0.35; 'but': 0.35; 'passwords': 0.36; 'hi,': 0.36; 'half': 0.37; 'skip:o 20': 0.38; 'e.g.': 0.38; 'tired': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'number,': 0.60; 'skip:c 50': 0.60; 'tell': 0.60; 'length': 0.61; 'matter': 0.61; "you're": 0.61; 'more': 0.64; 'between': 0.67; 'header:Reply-To:1': 0.67; 'brain': 0.68; 'reply-to:no real name:2**0': 0.71; 'obvious': 0.74; 'day': 0.76; 'reply- to:addr:python.org': 0.84; 'working,': 0.84; 'hands': 0.96 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=C6LQl2/+ c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=OJn0C7AadrgA:10 a=BCgJous8psMA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=DLy9r2xQ4g4A:10 a=gflGBsFcq_FoTV_IjhgA:9 a=hBqab-nAMjo5GTCg:21 a=u1cJxF2amSZd_Gyl:21 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Wed, 27 Nov 2013 17:44:03 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Cracking hashes with Python References: <0a4ae59b-fff8-40dd-b264-823ea596ad82@googlegroups.com> <52940dbe$0$11089$c3e8da3@news.astraweb.com> <2a8225b8-da33-4db4-b83b-dcbd8a619f6c@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 71 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385574233 news.xs4all.nl 15919 [2001:888:2000:d::a6]:47854 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60625 On 27/11/2013 12:40, TheRandomPast . wrote: > Hi, > > So apparently when I've been staring at code all day and tired my brain > doesn't tell my hands to type half of what I want it to. I apologise for > my last post. > > This is my code; > > import md5 > import sys > > characters=range(48,57)+range(65,90)+range(97,122) > > def chklength(hash): > if len(hash) != 32: > print '[-] Improper length for md5 hash.' > sys.exit(1) > > def checkPassword(password): > #print password > m = md5.new(password) > if (m.hexdigest() == hash): > print "match [" + password + "]" > sys.exit() > def recurse(width, position, baseString): > for char in characters: > if (position < width - 1): > recurse(width, position + 1, baseString + "%c" % char) > checkPassword(baseString + "%c" % char) > print "Target Hash [" + hash+ " string: "+ baseString > > def brute_force(): > maxChars = 32 > for baseWidth in range(1, maxChars + 1): > print "checking passwords width [" + `baseWidth` + "]" > recurse(baseWidth, 0, "") > > def dictionary(): > for line in File.readlines(): > checkPassword(line.strip('\n')) > hash =raw_input("Input MD5 hash:") > option=raw_input("Choose method:1=Brute Force; 0=Dictionary") > if(option==1): > chklength() > brute_force() > else: > if(option==0): > File=open("C:\dictionary.txt") > chklength() > dictionary() > else: > print "Wrong method!" > > And dictionary is working, as is the brute force however the issue I > have having is with my chklength() as no matter how many characters I > input it skips the !=32 and goes straight to asking the user to chose > either Brute Force or Dictionary. I want an error to be shown if the > hash is less than or more than 32 characters but at present this > chklength() doesn't work as I thought it would. > > Can anyone point out an obvious error that I am missing? > [snip] You're asking for the hash, then you're asking for the method. You're not checking the length of the hash between the two. BTW, 'raw_input' returns a string and a string != a number, e.g. "1" != 1.