Cryptography
Methodology
- Description and hints/try to determine topic
Scripts
Tools
Practice
Links
Topics
Ciphers
- Cipher Identifier
- Most ciphers can be found on this website
- Ciphey
Hashes
SHA1
XOR
Symmetric
ECB
CBC
CTR
GCM
Asymmetric
Modular arithmetic
- Coprime:
GCD(a, b) = 1
- Euclidean algorithm
- Extended Euclidean algorithm
- Multiplicative inverse:
multinv(a, b) = x -- (a * x) % b = 1
- Fermat’s little theorem:
pow(a, p, p) = a
andpow(a, p - 1, p) = 1
- Legendre symbol
pow(q, (p - 1) // 2, p) == 1
meanspow(a, 2, p) = q
exists- if
p % 4 == 3
then we can recovera
withpow(q, (p + 1) // 4, p)
- else
p % 4 == 1
, use Tonelli–Shanks algorithm square_root_mod_prime(Mod(a, p))
RSA
- encrypt:
c = pow(m, e, n)
- decrypt:
m = pow(c, modinv(e, (p - 1) * (q - 1)), n)
- RSA Examples
- Featherduster
- RSACtfTool
- RSA Attacks
- factorize primes (FactorDB)
- weiner (d is small)
- no padding
- small primes
- small e
- multiple messages with same e
- adjacent primes
- If
N == p^2
, the totient calculation isp(p - 1)
Broadcast attack
- Common variant: e == 3 and the same message is encrypted 3 times with 3 different values for N
- RSA Examples
- Writeup
- Another writeup
Chinese Remainder Theorem
DSA
Rabin
- Wikipedia
- e = 2
Linear Congruential Generator (LCG)
- Wikipedia
x_1 = (A * x_0 + B) % m
- Example problem
Keys
PEM
1
2
3
4
5
6
# Print values from PEM
from Crypto.PublicKey import RSA
print(RSA.importKey(open("a.pem", "rb").read()).d)
# ssh-keygen convert to PEM
ssh-keygen -f key.pub -e -m pem
OpenSSL
- Cheatsheet
openssl rsa -in private.key -text -noout
openssl rsa -pubin -noout -text < public.key
This post is licensed under
CC BY 4.0
by the author.