Last active
February 7, 2023 19:49
-
-
Save nickyreinert/00d631fe9a90108924b1df6e911c8cd5 to your computer and use it in GitHub Desktop.
Step-by-Step implementation of the SHA-256 algorithm in Python
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for word in result:\n", | |
" print(bin(int(word, 2))[2:].zfill(8) + '', end = '')\n", | |
"\n", | |
"print()\n", | |
"\n", | |
"for word in result:\n", | |
" print(hex(int(word, 2))[2:].zfill(8) + '', end = '')\n", | |
"\n", | |
"import hashlib\n", | |
"print()\n", | |
"print(hashlib.sha256(message.encode()).hexdigest())" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.9.13 (main, May 24 2022, 21:28:31) \n[Clang 13.1.6 (clang-1316.0.21.2)]" | |
}, | |
"orig_nbformat": 4, | |
"vscode": { | |
"interpreter": { | |
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Hello, i got message that this notebook is invalid. I can not open it in jupyter. Thanks for your help!
Edit: now I put the lines manually in jupyter but after loop #47 i got following message:
Can you fix it please? Thanks
You are right, I fixed it. I pasted the code instead of the raw text content of the Jupyter file.
Regarding your error: It works when I run it locally. Maybe it helps to run everything in one Jupyter. I splitted it to make it easier to implement in the Medium article. I uploaded the merged version here: https://gist.github.com/nickyreinert/5621d17d63efbbd68584246d20fe4d2f
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, i got message that this notebook is invalid. I can not open it in jupyter.
Thanks for your help!
Edit: now I put the lines manually in jupyter but after loop #47 i got following message:
Can you fix it please? Thanks