Skip to content

Add Extended GCD operation#2206

Open
p-leriche wants to merge 4 commits intogchq:masterfrom
p-leriche:extendedgcd
Open

Add Extended GCD operation#2206
p-leriche wants to merge 4 commits intogchq:masterfrom
p-leriche:extendedgcd

Conversation

@p-leriche
Copy link

@p-leriche p-leriche commented Feb 25, 2026

Description

Implements the Extended Euclidean Algorithm, computing the greatest common divisor (GCD) and Bézout coefficients for two integers.

Changes

  • Add ExtendedGCD.mjs operation
  • Update Categories.json to include Extended GCD in Arithmetic/Logic category

Functionality

Finds integers x and y such that: a·x + b·y = gcd(a, b)

This is fundamental for:

  • Modular inverse computation
  • Solving linear Diophantine equations
  • RSA key generation
  • Other number theory applications

Features

  • Supports decimal and hexadecimal input (0x prefix)
  • Handles arbitrarily large integers using BigInt
  • Iterative implementation (no recursion limits)
  • Clear output showing GCD, Bézout coefficients, and verification equation
  • Output formatted for readability with crypto-grade large integers

Dependencies

Depends on #2205

Testing

  • Tested with small coprime integers
  • Tested with non-coprime integers
  • Tested with crypto-grade large integers (2048+ bit)
  • Verified mathematical correctness (a·x + b·y = gcd)
  • Built successfully with npm run build

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant