Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'represents': 0.05; 'subject:Python': 0.06; 'error:': 0.07; 'fixes': 0.07; 'assuming': 0.09; 'bytes,': 0.09; 'terminated': 0.09; 'throws': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bug': 0.12; 'itself.': 0.14; 'better?': 0.16; 'collections': 0.16; 'did.': 0.16; 'display,': 0.16; 'hashes': 0.16; 'iterable,': 0.16; 'losing': 0.16; 'meanwhile,': 0.16; 'patches': 0.16; 'phase,': 0.16; 'programmer,': 0.16; 'sys.exit(0)': 0.16; 'sys.exit(1)': 0.16; 'typeerror:': 0.16; 'version;': 0.16; 'whitespace.': 0.16; 'all.': 0.16; 'wrote:': 0.18; '(not': 0.18; 'code.': 0.18; 'wed,': 0.18; 'trying': 0.19; 'things.': 0.19; 'value.': 0.19; 'thanks.': 0.20; 'help.': 0.21; 'code,': 0.22; '(in': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'adds': 0.24; "aren't": 0.24; 'unicode': 0.24; 'fairly': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'query': 0.26; 'somewhere': 0.26; 'supported': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; '(this': 0.29; 'am,': 0.29; 'character': 0.29; 'words': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'work.': 0.31; '(which': 0.31; 'code': 0.31; 'getting': 0.31; 'comments': 0.31; 'easier': 0.31; 'posting': 0.31; 'that.': 0.31; 'ball': 0.31; 'bunch': 0.31; 'file': 0.32; 'stuff': 0.32; 'option': 0.32; "we're": 0.32; 'run': 0.32; 'up.': 0.33; 'url:python': 0.33; 'running': 0.33; 'skip:& 30': 0.33; 'maybe': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'board': 0.35; 'except': 0.35; 'case,': 0.35; 'good.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; "i'll": 0.36; 'url:org': 0.36; 'being': 0.38; 'skip:o 20': 0.38; 'sometimes': 0.38; 'skip:& 10': 0.38; 'nov': 0.38; 'version,': 0.38; 'list,': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'functional': 0.39; 'sure': 0.39; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'hope': 0.61; 'new': 0.61; 'course': 0.61; 'simply': 0.61; "you're": 0.61; 'you.': 0.62; "you've": 0.63; 'teaching': 0.64; 'charset:windows-1252': 0.65; 'life': 0.66; 'side': 0.67; 'between': 0.67; 'hang': 0.67; '26,': 0.68; 'to,': 0.72; '3.4': 0.84; 'clearer': 0.84; "it'd": 0.84; 'studying': 0.84; '1:18': 0.91; 'to:none': 0.92; 'differences': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gVBSYmz58cwd5MZ+eulEivos5S15FjlwTr1DMqTeFJk=; b=yN2EHOEvU6ZJHa7jiwhe0ekm/ODqHxoIJcuprLprWC+2K+arb8uhvVyTMpsXO9sm+z bjepom4CJe4gu5Wjmp+h8apPci07BFoTutCR/zMw/lHmVwBARUL/DT4TwcV9ohaxO6wb MlfP4mJLw03iZVfRRG8Lgxs8SdFiAJAaCYiodw1RYS9pcKYIbUpJoAhyIVHZdHC73I2a p2VAiTapDTISDpQMIfz/5TNZaflNvK8STrjgAr0BIJ1WgxU7kJO8N07vj0mHwbcrCeIc ylXXIIRCEwE9AwGtZxxws2jOh+S4wM2kVYyczzCIBYtf6TH3o46nBpgytTmRJkka7HYI wI5Q== MIME-Version: 1.0 X-Received: by 10.180.77.74 with SMTP id q10mr18531375wiw.65.1385478823792; Tue, 26 Nov 2013 07:13:43 -0800 (PST) In-Reply-To: References: <0a4ae59b-fff8-40dd-b264-823ea596ad82@googlegroups.com> <52940dbe$0$11089$c3e8da3@news.astraweb.com> <2a8225b8-da33-4db4-b83b-dcbd8a619f6c@googlegroups.com> Date: Tue, 26 Nov 2013 15:13:43 +0000 Subject: Re: Cracking hashes with Python From: "TheRandomPast ." Cc: python-list@python.org Content-Type: multipart/alternative; boundary=f46d043bdf6a22de8f04ec15ed2c X-Mailman-Approved-At: Tue, 26 Nov 2013 16:19:56 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 194 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385479197 news.xs4all.nl 15961 [2001:888:2000:d::a6]:48653 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60520 --f46d043bdf6a22de8f04ec15ed2c Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Thanks. I'll take that on board and let you know how I get on. Thanks for all your help. On Tue, Nov 26, 2013 at 2:46 PM, Chris Angelico wrote: > On Wed, Nov 27, 2013 at 1:18 AM, TheRandomPast . > wrote: > > This is my code. I hope it looks better? I'm sorry if it doesn't. I'm > trying > > to get the hang of posting by email :) > > There are no BBCode tags here, so [code] doesn't help you at all. > Other than that, looks good. Though if you're going to annotate your > code, please mark your comments with a hash; that way, we can simply > copy and paste your code and run it, which is a huge help. (In this > case, I can see what's going on without running it, but that's not > always true. Sometimes my crystal ball is faulty.) > > > wordlist =3D open('C:/dictionary.txt') > > try: > > words =3D wordlist > > except(IOError): > > print "[-] Error: Check your path.\n" > > sys.exit(1) > > This now is functional but completely useless. You can drop this whole > block of code. > > > words =3D open('C:/dictionary.txt') > > print "\n",len(words),"words loaded=85" (This line now throws up an err= or > > where it wasn't before: TypeError: object of type 'file' has no len() > > The problem is that you've left out the readlines() call, so you now > aren't looking at a list, you're looking at the file object itself. > But take heart! A file object is iterable, so as long as you don't > mind losing this line of status display, it'll all work. > > > for word in words: > > hash =3D hashlib.md5(word[:-1]) > > value =3D hash.hexdigest() > > This is all very well, but you actually don't do anything with the > hash and the value. Tip: This would be a good place to stash them all > somewhere so you can look them up quickly. > > Side point: You're currently assuming that each word you get is > terminated by exactly a single newline. It'd be clearer to, instead of > slicing off the last character with the smiley [:-1] (not sure what > that represents - maybe he has a pen lid sticking out of his mouth?), > try stripping off whitespace. Strings have a method that'll do that > for you. > > > if hashes =3D=3D value: > > print "[+] Password is:"+word,"\n" > > sys.exit(0) > > This is where you'd look up in what you've stashed, except that at no > point before this do you query the user for the hash to look up. > > I recommend you think in terms of an initialization phase, and then a > loop in which you ask the user for input. That would be the most > normal way to do things. As it is, there's no loop, so having an > "exit" option is actually fairly useless. > > By the way, are you also learning about Python 3, or are you > exclusively studying Python 2? Python 2 is now a dead end; no new > features are being added to it, and it's to be supported with some bug > fixes for a while, and then security patches only after that; > meanwhile, Python 3 just keeps on getting better. We're now able to > play with a beta of 3.4 that adds a bunch of fun stuff above 3.3 > (which added a veritable ton of awesomeness over 3.2), and there are > features slated for 3.5 after that. Even if your course is teaching > only the old version, it'd be good for you, as a programmer, to > explore the differences in the new version; the sooner you get your > head around the difference between Unicode strings and collections of > bytes, the easier your life will be, and Py3 makes that distinction a > lot clearer than Py2 did. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > --f46d043bdf6a22de8f04ec15ed2c Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Thanks. I'll take that on board and let you know how I= get on.

Thanks for all your help. =A0


On Tue, Nov 26, 201= 3 at 2:46 PM, Chris Angelico <rosuav@gmail.com> wrote:
On Wed, Nov 27, 2013 at 1:= 18 AM, TheRandomPast .
<wishingforsam@gmail.com&= gt; wrote:
> This is my code. I hope it looks better? I'm sorry if it doesn'= ;t. I'm trying
> to get the hang of posting by email :)

There are no BBCode tags here, so [code] doesn't help you at all.=
Other than that, looks good. Though if you're going to annotate your code, please mark your comments with a hash; that way, we can simply
copy and paste your code and run it, which is a huge help. (In this
case, I can see what's going on without running it, but that's not<= br> always true. Sometimes my crystal ball is faulty.)

> wordlist =3D open('C:/dictionary.txt')
> try:
> =A0 =A0 words =3D wordlist
> except(IOError):
> =A0 =A0 print "[-] Error: Check your =A0path.\n"
> =A0 =A0 sys.exit(1)

This now is functional but completely useless. You can drop this whol= e
block of code.

> words =3D open('C:/dictionary.txt')
> print "\n",len(words),"words loaded=85" (This line= now throws up an error
> where it wasn't before: TypeError: object of type 'file' h= as no len()

The problem is that you've left out the readlines() call, so you = now
aren't looking at a list, you're looking at the file object itself.=
But take heart! A file object is iterable, so as long as you don't
mind losing this line of status display, it'll all work.

> for word in words:
> =A0 =A0 hash =3D hashlib.md5(word[:-1])
> =A0 =A0 value =3D hash.hexdigest()

This is all very well, but you actually don't do anything with th= e
hash and the value. Tip: This would be a good place to stash them all
somewhere so you can look them up quickly.

Side point: You're currently assuming that each word you get is
terminated by exactly a single newline. It'd be clearer to, instead of<= br> slicing off the last character with the smiley [:-1] (not sure what
that represents - maybe he has a pen lid sticking out of his mouth?),
try stripping off whitespace. Strings have a method that'll do that
for you.

> if hashes =3D=3D value:
> =A0 =A0 print "[+] Password is:"+word,"\n"
> =A0 =A0 sys.exit(0)

This is where you'd look up in what you've stashed, except th= at at no
point before this do you query the user for the hash to look up.

I recommend you think in terms of an initialization phase, and then a
loop in which you ask the user for input. That would be the most
normal way to do things. As it is, there's no loop, so having an
"exit" option is actually fairly useless.

By the way, are you also learning about Python 3, or are you
exclusively studying Python 2? Python 2 is now a dead end; no new
features are being added to it, and it's to be supported with some bug<= br> fixes for a while, and then security patches only after that;
meanwhile, Python 3 just keeps on getting better. We're now able to
play with a beta of 3.4 that adds a bunch of fun stuff above 3.3
(which added a veritable ton of awesomeness over 3.2), and there are
features slated for 3.5 after that. Even if your course is teaching
only the old version, it'd be good for you, as a programmer, to
explore the differences in the new version; the sooner you get your
head around the difference between Unicode strings and collections of
bytes, the easier your life will be, and Py3 makes that distinction a
lot clearer than Py2 did.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list

--f46d043bdf6a22de8f04ec15ed2c--