Skip to content

Instantly share code, notes, and snippets.

@CY0xZ
Created August 25, 2022 13:27
Show Gist options
  • Save CY0xZ/daaa2c95d108c5e811325f9bfa0466e0 to your computer and use it in GitHub Desktop.
Save CY0xZ/daaa2c95d108c5e811325f9bfa0466e0 to your computer and use it in GitHub Desktop.
FastWalletCreator_LowEntropyHex.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "FastWalletCreator_LowEntropyHex.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyONOuSiSbSKRw9KxVMEFfDw",
"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/CY0xZ/daaa2c95d108c5e811325f9bfa0466e0/fastwalletcreator_lowentropyhex.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"pip install eth_keys"
],
"metadata": {
"id": "Hnn6D4N9Lxsg"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "VvvLNSl1LwhG"
},
"outputs": [],
"source": [
"from eth_keys import keys\n",
"from eth_utils import decode_hex\n",
"\n",
"def EntropyHex(z):\n",
"\n",
" import os\n",
" import hashlib # for SHA256 computation\n",
" import binascii # for conversion between Hexa and bytes\n",
" entropy = binascii.b2a_hex(os.urandom(z))\n",
" data = entropy.strip() # cleaning of data\n",
" data = binascii.unhexlify(data)\n",
" h = hashlib.sha256(data).hexdigest()\n",
" return h , entropy\n",
"\n",
"random_key, entropy = EntropyHex(1)\n",
"priv_key_bytes = decode_hex('0x'+random_key)\n",
"priv_key = keys.PrivateKey(priv_key_bytes)\n",
"pub_key = priv_key.public_key\n",
"\n",
"print(\"Entropy:\",entropy)\n",
"print(\"Random Key Generated:\",random_key)\n",
"print(\"Private Key:\", priv_key)\n",
"print(\"Public Key:\", pub_key)\n",
"print(\"Public Address:\", pub_key.to_checksum_address())"
]
}
]
}
@CY0xZ
Copy link
Author

CY0xZ commented Aug 21, 2023

pip install eth-hash[pycryptodome]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment