Most encryption is based heavily on number theory, most of it being abstract algebra. Calculus and trigonometry isn't heavily used. Additionally, other subjects should be understood well; specifically probability (including basic combinatorics), information theory, and asymptotic analysis of algorithms. There's also more math that's worth knowing to be a good programmer which is key if you really want to be an expert. The number theory is more important with understanding asymmetric encryption, but does come up in symmetric encryption as well (e.g., in AES how to derive the S-box and MixColumns relates to understanding Galois fields).
First, you need to learn some notation. Things like logical operators, most importantly for cryptography XOR (sometimes denoted as circle plus: ⊕), where 0 XOR 1 = 1 XOR 0 = 1, and 0 XOR 0 = 1 XOR 1 = 0. It also helps to be able to understand the notation and language of abstract mathematics and set theory; e.g., {0,1}128 means the set of all strings that are made up of 128 binary digits (each digit is a 0 or 1). Similarly, F: {0,1}64 → {0,1}128 means F is a function that maps a 64 bit input into an output that is 128-bit string. You'll have to learn the difference between a function, bijection, permutation, etc, but again this is mostly just terminology of relatively simple concepts.
One of the most important topics is modular arithmetic. E.g., 1 ≡ 64 (mod 21)
where (mod N)
means you only care about the remainder when dividing by N (since 64/21 = 3 with remainder 1; the modulo is 1). One important notation to learn (that's a potential source of confusion) is that the (mod N)
applies to both sides of the equation; so you could equivalently say 8^2 ≡ 1 (mod 21)
. Many programming languages (e.g., C, Java, python, javascript) use %
to do modulo division -- e.g., 64 % 21
gives 1
. The cool thing about modular arithmetic is that you can just do normal arithmetic (addition and multiplication) and reduce at the end (or at any step in the middle) as modular arithmetic forms a finite field; e.g., 8 ≡ 29 ≡ 50 (mod 21) so since 8*8 ≡ 64 ≡ 1 (mod 21)
we also know that 29*8 = 232 ≡ 29*50 = 1450 ≡ 1 (mod 21)
. With modular arithmetic there's no difference both 8, 29, 50 represent the exact same number.
You'll need to understand things like Fermat's little theorem, Euler's theorem (based on totient), Euclid's algorithm for greatest common denominators (specifically Euclid's extended algorithm to generate multiplicative inverses), Carmichael numbers, Fermat primality test, Miller-Rabin primality test, modular exponentiation, and discrete logarithms.
If you want to go further you may want to learn about things like finite fields (specifically Galois fields), polynomial rings, elliptic curves, etc. This isn't meant to limit things; e.g., cryptography (and attacks on cryptography) aren't necessarily limited to these types of math. E.g., NUTRUEncrypt is based on lattices/shortest vector problem, and the McEliece Cryptosystem is based on Goppa codes, but again you still need to learn the math above to be able to understand this math.
And then you have the basic math background to learn about cryptography, which isn't just the math but also involves using the math in secure ways. (For example, textbook RSA c = m^e mod p q
is insecure for a variety of reasons - you should use a secure randomized padding scheme to your message and likely combine with symmetric encryption for long messages).
Free Electronic References
The Handbook of Applied Cryptography - Chapter 2 has a decent introduction to these concepts for the advanced learner -- it introduces concepts very quickly and compactly, and is probably better as a reference or second/third attempt at the material.
Chapter 1 of Algorithms by DPV (specifically sections 1.2 to 1.4) give a gentler introduction to the math behind RSA. (2015 Update: This pre-print of the book appears to be have taken off the one of the authors' academic website. The good textbook is available for purchase on amazon. I believe you can still find the book for free via google search for "Dasgupta Papadimitriou Vazirani algorithms pdf", though I am not directly linking as I am not sure it is being shared by a copyright holder with authority to legally share the book.)
Shoup - A Computational Introduction to Number Theory and Algebra - From the preface "Number theory and algebra play an increasingly significant role in computing and communications, as evidenced by the striking applications of these subjects to such fields as cryptography and coding theory. My goal in writing this book was to provide an introduction to number theory and algebra, with an emphasis on algorithms and applications, that would be accessible to a broad audience." Very detailed and fairly accessible.
Stick-figure introduction to AES at various levels of complexity with the last level showing where the number theory goes in.
The Udacity Applied Crypto course. More of an introduction to the cryptography than the math behind it, but introduces the math when necessary.
- Dan Boneh's Coursera cryptography course. Solid introduction to cryptography, again introducing the math when necessary.