About this Book#
Table of Contents#
Chapters
- 1. What is Cryptography?
- 2. Introduction to Python, Sage, and Jupyter Notebooks
- 3. Number Theory
- 4. Modular Arithmetic
- 5. Powers in \(\mathbb{Z}/m\mathbb{Z}\)
- 6. Discrete Logs, Diffie-Hellman Key Exchange, and the ElGamal Cryptosystem
- 7. Computing Discrete Logs
- 8. The Chinese Remainder Theorem and Generalized Bezout’s Lemma
- 9. Improvements on Computations of Discrete Logs
- 10. The RSA Cryptosystem
- 11. Primality Testing
- 12. Factorization
- 13. Square Roots Modulo \(m\)
- 14. Quadratic Sieve and Index Calculus
- 15. Digital Signatures
- 16. Elliptic Curves
- 17. Finite Fields and the Advanced Encryption Standard (AES)
Endmatter
Introduction#
This book is an introduction to the main mathematical and computational ideas in cryptography. It is heavily based on selected sections of An Introduction to Mathematical Cryptography, by Jeffrey Hoffstein, Jill Pipher, and Joseph H. Silverman, which is an excellent introduction to mathematical cryptography. In fact, we strongly recommend the more mathematically inclined readers to use that book in addition to (or perhaps even instead of) this present one. This book does not go nearly as deep in the math, but focus more in computations and applications. For example, we might just give computational evidence that some mathematical statement is true, rather than giving an actual proof. We do prove the easier statements, though, and although these could be skipped by the reader with less interest in the mathematics, we urge them to at least try read them, even if only superficially enough to have a general idea of why the statement is true.
This book was written to serve as a text book for CYBR 201 - Introduction to Cryptography and Data Protection at the University of Tennessee, which the author proposed and developed.
Goal#
The main goal of this book is to introduce the mathematical ideas behind cryptosystems and digital signature methods, but with a very practical and computational approach and with minimal prerequisites in mathematics. By following this book, the reader should be able to understand the underlying mathematical problems on which the security of cryptosystems and digital signatures are based, and the computational challenges associated to them.
We hope that by following this book, the more mathematically inclined, but with less experience with coding, should realize the difficulties of finding efficient methods for computations of even the most basic mathematical objects. Finding these methods requires a shift on how we think about mathematical problems.
On the other hand, the more computationally inclined readers, but with less mathematical background, should realize that mathematical insights quite often yield much greater gains than any clever coding.
Those who are just starting with both the math and programming at this level will hopefully appreciate the important relation between the two approaches in a very practical and concrete setting.
This way, we hope that all these groups should benefit from this book.
Topics#
The main goal it to cover the following applications:
the ElGamal Cryptosystem,
the RSA Cryptosystem,
and the Advanced Encryption Standard (AES).
We will also discuss the main methods of attack to these, by discussing efficient methods for factorization and computing discrete logs, such as:
Collision (Shank’s Baby-Step/Giant-Step Algorithm) (for computing discrete logs),
the Pohlig-Hellman Algorithm (for computing discrete logs),
Index Calculus (for computing discrete logs in \(\mathbb{F}_p^{\times}\)),
the Quadratic Sieve.
To properly cover this topics, we need to cover some basic Number Theory, including:
Greatest Common Divisor, including the Euclidean Algorithm and Extended Euclidean Algorithm,
Integers Modulo \(m\) and its units,
Primality Testing (including the Miller-Rabin Probabilistic Test),
and related computational problems.
We will also have a very practical approach when covering this theory. Although we will provide proofs to the simpler results, we often will just demonstrate statements with some concrete computations. Concrete examples will also be provided to illustrate the statements. Moreover, the computations will always be done with the help of Sage. Hence, although our goal is to illustrate the importance of mathematics in cryptography, we do not require any higher-level background in mathematics.
We will also give a brief introduction to the basic tools of Python and Sage necessary for the course.
Computations#
There is a large focus on computations, since the challenges involved in creating and breaking cryptosystems are computational in nature. Therefore we will focus on computational methods in Number Theory, the main mathematical background for the cryptosystems introduced here. We will discuss many methods and algorithms, but always with a practical goal.
We will not assume any previous background in Number Theory, but we will introduce the needed results as we progress.
Sage#
We will use Sage as the main programming language for our examples. Sage is based on Python, which is a simple and yet powerful programming language, often taught as a first programming language. Sage uses the same syntax as Python, so it should be easy for those who already know Python to use Sage, while been a suitable introduction to programming as well.
Sage adds a lot more mathematical functionality to Python out of the box, making the implementation and testing of the methods in this book a lot easier, when compared to plain Python.
As with Python, Sage if free and open source. It can be installed directly in the users computer or used online with Cocalc.
We will not assume that the reader has any previous experience with coding, and introduce the necessary background in the text. But experience with coding, especially in Python, would certainly benefit the reader.
Homework#
We suggest the reader complete the corresponding homework assignments. These implement methods and algorithms described in the text, and therefore are computational (rather than purely mathematical) in nature. The goal is to reinforce the ideas introduced and allow the reader to experience the difficulties and efficiency differences between different methods.
These are available as Jupyter Notebooks that should be run using Sage as the kernel. These notebooks will not work with pure Python!
Most routines that the reader will implement are available in Sage already, and in fact these will be used to test the reader’s code in the homework. But, again, the goal is not to have the final product/tool, it is to understand how these methods work, what they involve, what is the math behind it, and to see in them working in practice.
Hopefully the homework give the reader practice with coding, with a particular care about efficiency.
Source Notebooks#
The source Jupyter notebooks from each chapter used to create this book can be downloaded directly from the official site https://luisfinotti.org/pcimc/. Just click on the Download icon on the top of the page and choose .ipynb.
Important: To be able to run this properly, a Sage kernel must be used. And, for the notebook to be displayed correctly, the JupyterLab MyST Extension must be installed in the system.
Unfortunately, the links to different notebooks will not work.
Corrections#
Please send any typos, corrections (mathematical or grammatical), problems, and suggestions to luis@luisfinotti.org.
Acknowledgments#
The book An Introduction to Mathematical Cryptography, by Jeffrey Hoffstein, Jill Pipher, and Joseph H. Silverman, was the main resource for this book, along with class notes from the author on a course based in that book.
This book was produced using Jupyter notebooks and Jupyter Book. MyST Markdown (and LaTeX) were used to type and render the text. The computations were done with Sage.
This book was written during a semester in which the College of Emerging and Collaborative Studies at the University of Tennessee reduced the author’s teaching load, allowing the writing of this book. The teaching reduction was given so the author could develop the new course CYBR 201 - Introduction to Cryptography and Data Protection, and although writing the book was not a requirement, the extra time allowed the author to do it. Therefore, the author would like to thank the University of Tennessee, the College of Emerging and Collaborative Studies , and UT’s Math Department for their support.
Copyright#
This book is protected by United States and International copyright laws. Reproduction and distribution without the consent of the author is prohibited. You may contact the author at luis@luisfinotti.org.
Copyright © 2025 Luís R.A. Finotti. All rights reserved.