Created
May 9, 2024 00:24
-
-
Save rezamarzban/7660f13d53477ec2467bbc3372575a44 to your computer and use it in GitHub Desktop.
html.ipynb
This file contains 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"authorship_tag": "ABX9TyMHNCVBhjLVeRB9Jzb26IYz", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/rezamarzban/7660f13d53477ec2467bbc3372575a44/html.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "kqNmLyhTueqn" | |
}, | |
"outputs": [], | |
"source": [ | |
"\n", | |
"import hashlib\n", | |
"import itertools\n", | |
"from tqdm import tqdm\n", | |
"\n", | |
"def calculate_checksum(string):\n", | |
" return hashlib.sha256(string.encode()).hexdigest()\n", | |
"\n", | |
"def generate_strings_with_checksum(target_checksum, characters, string_length):\n", | |
" for candidate in itertools.product(characters, repeat=string_length):\n", | |
" candidate_str = ''.join(candidate)\n", | |
" checksum = calculate_checksum(candidate_str)\n", | |
" if checksum == target_checksum:\n", | |
" return candidate_str\n", | |
" return None\n", | |
"\n", | |
"# Read target checksums from a text file\n", | |
"results = []\n", | |
"with open('checksums.md5', 'r') as file:\n", | |
" lines = file.readlines()\n", | |
" for line in tqdm(lines, desc=\"Processing\"):\n", | |
" target_checksum = line.strip()\n", | |
" characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=[]{}|;:,.<>?/~`\" '\n", | |
" string_length = 3\n", | |
" string = generate_strings_with_checksum(target_checksum, characters, string_length)\n", | |
" if string is not None:\n", | |
" results.append(string)\n", | |
"\n", | |
"# Print the results in a single line without spaces\n", | |
"final = \"\".join(results)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"\n", | |
"from IPython.display import HTML\n", | |
"import base64\n", | |
"\n", | |
"html_text = base64.b64decode(final).decode(\"utf-8\")\n", | |
"\n", | |
"display(HTML(html_text))" | |
], | |
"metadata": { | |
"id": "NAwEsWnGujK3" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment