Part 6: Number Theory and Cryptography
The Security Incident That Taught Me Number Theory
token_id = int(time.time()) # Timestamp as token IDimport secrets
# Cryptographically secure random
token_id = secrets.randbelow(2**128) # 128-bit random number
# Or use prime field arithmetic
p = 2**127 - 1 # Mersenne prime
token_id = secrets.randbelow(p)Modular Arithmetic: Clock Mathematics
The Basics
Real Application: Hash Tables
Modular Exponentiation
Prime Numbers: Building Blocks of Cryptography
Testing for Primes
Generating Prime Numbers
Greatest Common Divisor (GCD)
Modular Multiplicative Inverse
RSA Encryption (Simplified)
Hashing and Checksums
Chinese Remainder Theorem
Real-World Application: Password Storage
Key Takeaways
What's Next
Navigation
Last updated