Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
duyuefeng0708
GitHub Repository: duyuefeng0708/Cryptography-From-First-Principle
Path: blob/main/foundations/01-modular-arithmetic-groups/README.md
483 views
unlisted

Module 01: Modular Arithmetic and Groups

View on nbviewer

From clock arithmetic to the algebraic structures that underpin all of cryptography.

Prerequisites

No prior modules needed. This is the starting point.

Learning Objectives

After completing this module you will:

  1. Understand modular arithmetic as a system, not just a calculation trick

  2. Recognize group structure in Z_n and Z_n*

  3. Compute generators and orders of cyclic groups

  4. Apply Lagrange's theorem to reason about subgroup structure

Two Ways to Run

Every notebook has two versions. Choose whichever works for you.

Python (browser)SageMath
SetupZero install, runs in JupyterLiteNeeds local install or Codespaces
Launch time~5 seconds~1 minute (Codespaces) or 10+ min (Binder)
Best forQuick exploration, mobile, first-timersFull algebra system, research-grade computations

Explore

Work through these notebooks in order:

#NotebookPythonSageMath
aIntegers and Divisionpythonsage
bModular Arithmeticpythonsage
cGroups: First Lookpythonsage
dCyclic Groups and Generatorspythonsage
eSubgroups and Lagrangepythonsage
fGroup Visualizationpythonsage

Implement (Rust)

Build these from scratch in rust/src/lib.rs:

#FunctionDescription
1mod_expModular exponentiation via repeated squaring
2gcdGreatest common divisor (Euclidean algorithm)
3is_generatorTest whether an element generates the full group
4element_orderCompute the multiplicative order of an element
5find_all_generatorsEnumerate every generator of Z_n*

Run: cargo test -p mod-arith-groups

Break

AttackPythonSageMath
Smooth-Order Attack (Pohlig-Hellman)pythonsage
Weak Generator Attackpythonsage

Connect

ApplicationPythonSageMath
RSA Key Generationpythonsage
Diffie-Hellman Parameter Selectionpythonsage

Next: Module 02: Rings, Fields, and Polynomials