{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "############## PLEASE RUN THIS CELL FIRST! ###################\n", "\n", "# import everything and define a test runner function\n", "from importlib import reload\n", "from helper import run\n", "import ecc\n", "import helper" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1\n", "\n", "Find the uncompressed SEC format for the Public Key where the Private Key secrets are:\n", "\n", "* 5000\n", "* \\\\(2018^{5}\\\\)\n", "* 0xdeadbeef12345" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 1\n", "\n", "from ecc import PrivateKey\n", "\n", "# 5000\n", "# 2018**5\n", "# 0xdeadbeef12345\n", "# privatekey.point is the public key for a private key" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 2\n", "\n", "Find the Compressed SEC format for the Public Key where the Private Key secrets are:\n", "\n", "* 5001\n", "* \\\\(2019^{5}\\\\)\n", "* 0xdeadbeef54321" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 2\n", "\n", "from ecc import PrivateKey\n", "\n", "# 5001\n", "# 2019**5\n", "# 0xdeadbeef54321" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3\n", "\n", "Find the DER format for a signature whose `r` and `s` values are:\n", "\n", "* r =\n", "\n", "`0x37206a0610995c58074999cb9767b87af4c4978db68c06e8e6e81d282047a7c6`\n", "\n", "* s =\n", "\n", "`0x8ca63759c1157ebeaec0d03cecca119fc9a75bf8e6d0fa65c841c8e2738cdaec`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 3\n", "\n", "from ecc import Signature\n", "\n", "r = 0x37206a0610995c58074999cb9767b87af4c4978db68c06e8e6e81d282047a7c6\n", "s = 0x8ca63759c1157ebeaec0d03cecca119fc9a75bf8e6d0fa65c841c8e2738cdaec" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 4\n", "\n", "Convert the following hex to binary and then to Base58:\n", "\n", "* `7c076ff316692a3d7eb3c3bb0f8b1488cf72e1afcd929e29307032997a838a3d`\n", "* `eff69ef2b1bd93a66ed5219add4fb51e11a840f404876325a1e8ffe0529a2c`\n", "* `c7207fee197d27c618aea621406f6bf5ef6fca38681d82b2f06fddbdce6feab6`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 4\n", "\n", "from helper import encode_base58\n", "\n", "# 7c076ff316692a3d7eb3c3bb0f8b1488cf72e1afcd929e29307032997a838a3d\n", "# eff69ef2b1bd93a66ed5219add4fb51e11a840f404876325a1e8ffe0529a2c\n", "# c7207fee197d27c618aea621406f6bf5ef6fca38681d82b2f06fddbdce6feab6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 5\n", "\n", "Find the address corresponding to Public Keys whose Private Key secrets are:\n", "\n", "* 5002 (use uncompressed SEC, on testnet)\n", "* \\\\(2020^{5}\\\\) (use compressed SEC, on testnet)\n", "* 0x12345deadbeef (use compressed SEC on mainnet)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 5\n", "\n", "from ecc import PrivateKey\n", "\n", "# 5002 (use uncompressed SEC, on testnet)\n", "# 2020**5 (use compressed SEC, on testnet)\n", "# 0x12345deadbeef (use compressed SEC on mainnet)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 6\n", "\n", "Find the WIF for Private Key whose secrets are:\n", "\n", "* 5003 (compressed, testnet)\n", "* \\\\(2021^{5}\\\\) (uncompressed, testnet)\n", "* 0x54321deadbeef (compressed, mainnet)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 6\n", "\n", "from ecc import PrivateKey\n", "\n", "# 5003\n", "# 2021**5\n", "# 0x54321deadbeef" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 7\n", "\n", "Write a function `little_endian_to_int` which takes Python bytes, interprets those bytes in Little-Endian and returns the number.\n", "\n", "#### Make [this test](/edit/code-ch04/helper.py) pass: `helper.py:HelperTest:test_little_endian_to_int`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 7\n", "\n", "reload(helper)\n", "run(helper.HelperTest(\"test_little_endian_to_int\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 8\n", "\n", "Write a function `int_to_little_endian` which does the reverse of the last exercise.\n", "\n", "#### Make [this test](/edit/code-ch04/helper.py) pass: `helper.py:HelperTest:test_int_to_little_endian`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 8\n", "\n", "reload(helper)\n", "run(helper.HelperTest(\"test_int_to_little_endian\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 9\n", "\n", "Create a testnet address for yourself using a long secret that only you know. This is important as there are bots on testnet trying to steal testnet coins. Make sure you write this secret down somewhere! You will be using the secret later to sign Transactions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exercise 9\n", "\n", "from ecc import PrivateKey\n", "from helper import hash256, little_endian_to_int\n", "\n", "# select a passphrase here, add your email address into the passphrase for security\n", "# passphrase = b'your@email.address some secret only you know'\n", "# secret = little_endian_to_int(hash256(passphrase))\n", "# create a private key using your secret\n", "# print an address from the public point of the private key with testnet=True" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 2 }