Created
November 24, 2014 13:23
-
-
Save balzer82/85f9fd79016f37f39b2e to your computer and use it in GitHub Desktop.
Why XKCD Comic about the 'correcthorsebatterystaple' password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:ae505b1f6f359c83b7cb065124e505db9a6b6179e071ae488fabf92a1377aac0" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import hashlib" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# diese Hash-Algorithmen sind \u00fcblich\n", | |
"hashlib.algorithms" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 2, | |
"text": [ | |
"('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')" | |
] | |
} | |
], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# diese Funktion wandelt Kennw\u00f6rter in Hashs um\n", | |
"def md5(pw):\n", | |
" return hashlib.md5(str(pw)).hexdigest()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# probieren wir es mal\n", | |
"md5('kennwort')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 18, | |
"text": [ | |
"'97ac58249ee2e4199920167d5e216b9a'" | |
] | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Hier eine Password-Datenbank" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"stolenpassworddatabase = {\n", | |
" 'user1': '098f6bcd4621d373cade4e832627b4f6',\n", | |
" 'user2': '5f4dcc3b5aa765d61d8327deb882cf99',\n", | |
" 'user3': '03aadf99da97bfedcbf57fd8484546a5',\n", | |
" 'user4': '54ac51eb226136ea0bd7ab01c85ef7c5'\n", | |
" }" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Hier die Kennw\u00f6rter, die wir testen wollen" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"trythisones = [\n", | |
" 'superkennwort',\n", | |
" 'A',\n", | |
" 'B',\n", | |
" 'RichtigerPferdeBatterieStapel',\n", | |
"]" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 20 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 2, | |
"metadata": {}, | |
"source": [ | |
"Hier die Funktion, die alles durchprobiert" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for pw in trythisones:\n", | |
" for username, passwordhash in stolenpassworddatabase.iteritems():\n", | |
" if md5(pw) == passwordhash:\n", | |
" print('Gefundener Zugang: \\'%s\\' mit Kennwort \\'%s\\'' % (username, pw))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Gefundener Zugang: 'user4' mit Kennwort 'superkennwort'\n" | |
] | |
} | |
], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 7 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment