<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 0xMouiz</title>
    <description>The latest articles on DEV Community by 0xMouiz (@mouiz).</description>
    <link>https://dev.to/mouiz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054855%2Fd32b6a76-0d8d-431b-8824-612115905061.jpeg</url>
      <title>DEV Community: 0xMouiz</title>
      <link>https://dev.to/mouiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mouiz"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>0xMouiz</dc:creator>
      <pubDate>Wed, 13 Aug 2025 03:53:23 +0000</pubDate>
      <link>https://dev.to/mouiz/-57g5</link>
      <guid>https://dev.to/mouiz/-57g5</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3" class="crayons-story__hidden-navigation-link"&gt;Building Bitcoin’s secp256k1 Curve and ECDSA from Scratch in Python&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/mouiz" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054855%2Fd32b6a76-0d8d-431b-8824-612115905061.jpeg" alt="mouiz profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/mouiz" class="crayons-story__secondary fw-medium m:hidden"&gt;
              0xMouiz
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                0xMouiz
                
              
              &lt;div id="story-author-preview-content-2769138" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/mouiz" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054855%2Fd32b6a76-0d8d-431b-8824-612115905061.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;0xMouiz&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 12 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3" id="article-link-2769138"&gt;
          Building Bitcoin’s secp256k1 Curve and ECDSA from Scratch in Python
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/blockchain"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;blockchain&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/bitcoin"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;bitcoin&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ethereum"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ethereum&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;3&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            2 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>python</category>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>Building Bitcoin’s secp256k1 Curve and ECDSA from Scratch in Python</title>
      <dc:creator>0xMouiz</dc:creator>
      <pubDate>Tue, 12 Aug 2025 05:54:54 +0000</pubDate>
      <link>https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3</link>
      <guid>https://dev.to/mouiz/building-bitcoins-secp256k1-curve-and-ecdsa-from-scratch-in-python-5ho3</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae1u7xcnqz3q4duni0kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fae1u7xcnqz3q4duni0kv.png" alt="Bitcoin’s secp256k1 Curve and ECDSA from Scratch in Python&amp;lt;br&amp;gt;
" width="720" height="615"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Elliptic curve cryptography (ECC) powers the security of Bitcoin, Ethereum, and countless secure systems.&lt;br&gt;
One of the most famous curves, &lt;em&gt;secp256k1&lt;/em&gt;, is the backbone of Bitcoin addresses and Ethereum keys.&lt;/p&gt;

&lt;p&gt;While libraries like &lt;em&gt;secp256k1&lt;/em&gt; and &lt;em&gt;ecdsa&lt;/em&gt; abstract away the math, building it yourself is a great way to understand how elliptic curves and ECDSA signatures work.&lt;/p&gt;

&lt;p&gt;In this post, we’ll walk through my minimal Python implementation of secp256k1 — covering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The math behind the curve&lt;/li&gt;
&lt;li&gt;Point addition, doubling, and scalar multiplication&lt;/li&gt;
&lt;li&gt;Private/public key generation&lt;/li&gt;
&lt;li&gt;ECDSA signing and verification with Keccak-256&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  1. What is secp256k1?
&lt;/h2&gt;

&lt;p&gt;secp256k1 is a Koblitz curve defined over a finite field. Its equation is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;y² ≡ x³ + 7 (mod p)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;p&lt;/em&gt; is a large prime&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;a&lt;/em&gt;=0, &lt;em&gt;b&lt;/em&gt;=7&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;G&lt;/em&gt; is the generator point&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;n&lt;/em&gt; is the order of the curve&lt;/li&gt;
&lt;li&gt;It’s used in Bitcoin, Ethereum, and other blockchain systems because it offers strong security and fast computation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  2. Implementing the Curve
&lt;/h2&gt;

&lt;p&gt;We start with a Point class for elliptic curve points, supporting:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Addition &lt;em&gt;(P+Q)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Doubling &lt;em&gt;(2P)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Scalar multiplication &lt;em&gt;(kP)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Point:
    def __add__(self, other):
        if self.is_at_infinity():
            return other
        if other.is_at_infinity():
            return self
        if self == other:
            return self.double()
        if self.x == other.x and (self.y + other.y) % self.curve.p == 0:
            return Point(None, None, self.curve)  # point at infinity
        s = ((other.y - self.y) * pow(other.x - self.x, -1, self.curve.p)) % self.curve.p
        x_r = (s**2 - self.x - other.x) % self.curve.p
        y_r = (s * (self.x - x_r) - self.y) % self.curve.p
        return Point(x_r, y_r, self.curve)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The Curve class enforces the curve equation and provides helper methods like _tangent_slope _for doubling.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. secp256k1 Parameters
&lt;/h2&gt;

&lt;p&gt;We define the constants exactly as per the official specification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
a  = 0
b  = 7
Gx = 0x79BE66...
Gy = 0x483ADA...
n  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
h  = 1

curve = Curve(a, b, p, n, h, Gx, Gy, "secp256k1")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Key Generation
&lt;/h2&gt;

&lt;p&gt;Private key: random integer in &lt;em&gt;[1,n−1]&lt;/em&gt;&lt;br&gt;
Public key: &lt;em&gt;priv × G&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  5. ECDSA Signing
&lt;/h2&gt;

&lt;p&gt;We use &lt;em&gt;Keccak-256&lt;/em&gt; for hashing (Ethereum’s choice) and the standard ECDSA formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sign(msg, private_key):
    z = int.from_bytes(keccak256(msg), "big")
    while True:
        k = secrets.randbelow(curve.n)
        R = k * curve.G
        r = R.x % curve.n
        s = (modinv(k, curve.n) * (z + r * private_key)) % curve.n
        if r != 0 and s != 0:
            return (r, s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. ECDSA Verification
&lt;/h2&gt;

&lt;p&gt;The verifier computes:&lt;br&gt;
&lt;em&gt;u1 = z × w&lt;/em&gt;&lt;br&gt;
&lt;em&gt;u2 = r × w&lt;/em&gt;&lt;br&gt;
&lt;em&gt;P = u1 × G + u2 × Q&lt;/em&gt;&lt;br&gt;
Valid if &lt;em&gt;Px mod n = r&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  7. Demo Run
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[+] Private key: 0x1393b6573adf24c61b73561768d9ea4ba1670dcc77554f25938cbca621ed7645
[+] Public key: 0475ca8eaf8393...
[+] Signature: (2313066..., 8090080...)
[+] Signature valid? True

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Why This Matters
&lt;/h2&gt;

&lt;p&gt;This code is &lt;strong&gt;not for production&lt;/strong&gt; — it’s educational.&lt;br&gt;
It shows exactly how:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bitcoin addresses are derived&lt;/li&gt;
&lt;li&gt;Ethereum signs transactions&lt;/li&gt;
&lt;li&gt;ECDSA math works without relying on “magic” library calls&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  9. Full Source Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/0xMouiz/python-secp256k1" rel="noopener noreferrer"&gt;https://github.com/0xMouiz/python-secp256k1&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>ethereum</category>
    </item>
  </channel>
</rss>
