Skip to content

Instantly share code, notes, and snippets.

@CY0xZ
Last active August 18, 2022 15:34
Show Gist options
  • Save CY0xZ/5e8d7faf89b4542af1105c1b298edbf8 to your computer and use it in GitHub Desktop.
Save CY0xZ/5e8d7faf89b4542af1105c1b298edbf8 to your computer and use it in GitHub Desktop.
WeakEntropy-Bin-Int-Hex.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "WeakEntropy-Bin-Int-Hex.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyNRfJzBG+QQmRmHK2fOtj81",
"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/CynegeticIO/5e8d7faf89b4542af1105c1b298edbf8/weakentropy-bin-int-hex.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"########################################################################################################\n",
"############################ GET WEAK ENTROPY TO GENERATE WEAK PK ######################################\n",
"########################################################################################################"
],
"metadata": {
"id": "C679QUK5j63C"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"pip install coincurve"
],
"metadata": {
"id": "7EyfAQwlWJbV"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def WeakEntropyHex():\n",
"\n",
" import hashlib # for SHA256 computation\n",
" import binascii # for conversion between Hexa and bytes\n",
" entropy = binascii.b2a_hex(os.urandom(16))\n",
" data = entropy.strip() # cleaning of data\n",
" data = binascii.unhexlify(data)\n",
" if len(data) not in [16, 20, 24, 28, 32]:\n",
" raise ValueError('Data length should be one of the following: [16, 20, 24, 28, 32], but it is not (%d).' % len(data))\n",
"\n",
" return data , entropy"
],
"metadata": {
"id": "8RjOcKAnVLGK"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def RandBin(p=32):\n",
"\n",
" import random\n",
" key = \"\"\n",
" for i in range(p):\n",
" temp = str(random.randint(0, 1))\n",
" key += temp\n",
" return(key)\n",
"\n",
"def WeakEntropyBin():\n",
"\n",
" import hashlib # for SHA256 computation\n",
" import binascii # for conversion between Hexa/bin and bytes\n",
" entropy = RandBin()\n",
" data = entropy.strip() # cleaning of data\n",
" data = binascii.unhexlify(data)\n",
" if len(data) not in [16, 20, 24, 28, 32]:\n",
" raise ValueError('Data length should be one of the following: [16, 20, 24, 28, 32], but it is not (%d).' % len(data))\n",
"\n",
" return data , entropy"
],
"metadata": {
"id": "jB548JqSgG_H"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def RandInt(p=32):\n",
"\n",
" import random\n",
" key = \"\"\n",
" for i in range(p):\n",
" temp = str(random.randint(0, 9))\n",
" key += temp\n",
" return(key)\n",
"\n",
"def WeakEntropyInt():\n",
"\n",
" import hashlib # for SHA256 computation\n",
" import binascii # for conversion between Hexa/bin and bytes\n",
" entropy = RandInt()\n",
" data = entropy.strip() # cleaning of data\n",
" data = binascii.unhexlify(data)\n",
" if len(data) not in [16, 20, 24, 28, 32]:\n",
" raise ValueError('Data length should be one of the following: [16, 20, 24, 28, 32], but it is not (%d).' % len(data))\n",
" \n",
" return data , entropy"
],
"metadata": {
"id": "yMSky5ZNb8cq"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from coincurve import PublicKey\n",
"from sha3 import keccak_256\n",
" \n",
"private_key, e = WeakEntropyInt()\n",
"public_key = PublicKey.from_valid_secret(private_key).format(compressed=False)[1:]\n",
"addr = keccak_256(public_key).digest()[-20:]\n",
"\n",
"print('private_key:', private_key.hex())\n",
"print('eth addr: 0x' + addr.hex())"
],
"metadata": {
"id": "HFRPxuJuU8c2"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "4lTVxmOMqjdZ"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment