Today I will briefly describe some key ideas that we've covered in
this course up until now.  Make sure you understand these, so you can
do well on the midterm, which is Wednesday, October 17, and is worth
20\% of your grade.

\section{Some Basic Definitions}
\hd{Greatest common divisor:}
$$\gcd(a,b) = \max\{ d : d \mid a \text{ and } d \mid b\}$$

\hd{Congruence:}
$a\con b\pmod{n}$ means that $n\mid a-b$.
\begin{example}
We have $7\con -19\pmod{13}$ since $13\mid 7-(-19)=26$.
\end{example}

If $a$ is an integer such that $\gcd(a,n)=1$, then the order
of~$a$ modulo~$n$ is 
$$\min\left\{ i\in\N  \,:\, a^i \con 1\pmod{n}\right\}.$$
For example, the order of~$2$ modulo $15$ is~$4$.

\hd{Some Rings and Groups:}
We let $\Z/n\Z$ denote the ring of equivalence classes of integers
modulo~$n$.  We also frequently consider the group
$$(\Z/n\Z)^* = \left\{ a \,:\, 1\leq a \leq n \text{ and }\gcd(a,n)=1\right\}.$$
The order of $a$ modulo~$n$ is then the order of the image of~$a$
in the multiplicative group $(\Z/n\Z)^*$.

%A quote: ``The hardest thing in number theory is finite abelian groups.''

\section{Equations Modulo~$n$}
\subsection{Linear Equations}
The equation $ax\con b\pmod{n}$ must have a solution if $\gcd(a,n)=1$.
{\em Warning:} It might still have a solution even if $\gcd(a,n)\neq 1$.  
\begin{example}
The equation $3x\con 2\pmod{5}$ has the solution $x=4$.\\
The equation $3x\con 9\pmod{18}$ has a solution $x=3$ even though
$\gcd(3,18)=3\neq 1$.
\end{example}

\subsection{Quadratic Equations}
Suppose~$a$ is an integer that is not divisible by~$p$.  The
solvability or nonsolvability of the quadratic equation $x^2\con
a\pmod{p}$ is addressed by quadratic reciprocity.  (So far we have
not discussed how to find a solution, only whether or not one exists.)
The quadratic residue symbol is
$$
\kr{a}{p} = \begin{cases} +1 & \text{ if $x^2\con a\pmod{p}$ has a solution }\\
                          -1 & \text{ otherwise}.
	    \end{cases}
$$
We have
$$\kr{a}{p} \con a^{(p-1)/2} \pmod{p}.$$
The {\bf Quadratic Reciprocity Law}, which was proved by Gauss, asserts that 
if~$p$ and~$q$ are distinct odd primes then
$$
\kr{p}{q} = (-1)^{\frac{p-1}{2}\cdot\frac{q-1}{2}}\kr{q}{p}.
$$
This is the deepest result that we've proved in the course so far.  On
the midterm, you will {\em not} be held responsible for understanding
the proof I gave last Friday.   However, you should know the statement of
the quadratic reciprocity law and have some practice applying it.

\section{Systems of Equations}
Suppose that $n$ and $m$ are coprime integers.  Then the
{\bf Chinese Remainder Theorem} (CRT) asserts that the system of equations
\begin{align*}
x & \con a \pmod{m},\\
x & \con b \pmod{n}
\end{align*}
has solutions.  (There is exactly one nonnegative solution $x<nm$.)
\begin{example}
Because of CRT, I know that there is an~$x$ such that
\begin{align*}
x &\con 1\pmod{37},\\
x &\con 17\pmod{23}
\end{align*}
even though I am too lazy to find~$x$ right now.
\end{example}


\section{The Euler $\vphi$ Function}
Define a function $\vphi: \N \ra \N$ by 
$$
  \vphi(n) = \#\{a : 1\leq a \leq  n \text{ and } \gcd(a,n) = 1\} = \#(\Z/n\Z)^*.
$$
Using the Chinese Remainder Theorem we proved that $\vphi$ is 
a {\em multiplicative function}, i.e., if $m, n\in\N$ and $\gcd(m,n)=1$, then
$$\vphi(mn) = \vphi(m)\cdot \vphi(n).$$
Also, if $p$ is a prime
then $\ds \vphi(p^n) = p^n - \frac{p^n}{p} = p^n-p^{n-1}$.
\begin{example}
$$\vphi(2^3\cdot 5^2) = \vphi(2^3)\cdot \vphi(5^2)
        = (2^3 - 2^2)\cdot (5^2-5) = 4\cdot 20 = 80.$$
\end{example}

\section{Public-key Cryptography}
\subsection{The Diffie-Hellman Key Exchange}
\begin{enumerate}
\item Nikita chooses a prime~$p$ and a number~$g$ 
that is a primitive root modulo~$p$.  She tells Michael both~$p$ and~$g$.
\item Nikita secretely chooses a random number~$n$ and
sends Michael $g^n\pmod{p}$.
\item Michael secretely chooses a random number~$m$ and
sends Nikita $g^m\pmod{p}$.
\item The {\em secret key} is $s=g^{nm}\pmod{p}$.  Both
Michael and Nikita can easily compute~$s$, but The Collective can't
because of the difficulty of the ``discrete logarithm problem''.
\end{enumerate}


\subsection{The RSA Cryptosystem}
\begin{enumerate}
\item Nikita creates her public key as follows:
\begin{enumerate}
\item She chooses two distinct large primes~$p$ and~$q$, then
computes both $n=pq$ and $\vphi(n) = (p-1)(q-1)$.  
\item She picks a random natural number $e<\vphi(n)$ such 
that $\gcd(e,\vphi(n))=1$.
\item She computes a number $d$ such that $ed\con 1\pmod{\vphi(n)}$.
\item Her public key is $(n,e)$.   (And her private decoding key is $d$.)
\end{enumerate}
\item To send Nikita a message, Michael encodes it (or a piece of it)
as a number $m\pmod{n}$.  He then sends $m^e\pmod{n}$ to Nikita. 
\item Nikita recovers $m$ from $m^e\pmod{n}$ by using that
      $$m \con (m^e)^d\pmod{n}.$$
\end{enumerate}

\section{Important Algorithms}
\subsection{Euclid's Algorithm}
Given integers $a$ and $b$, a slight extension of Euclid's gcd
algorithm enables us to find integers $x$ and $y$ such that
$$
   ax + by = \gcd(a,b).
$$
\begin{example}
$a=12$, $b=101$.
\begin{align*}
\ul{101}&=8\cdot \ul{12} + \ul{5} & \ul{5}&=\ul{101}-8\cdot \ul{12}\\
\ul{12} &=2\cdot\ul{5} + \ul{2}   & \ul{2} &= -2\cdot \ul{101} + 17\cdot \ul{12}\\
\ul{5}  &=2\cdot \ul{2}+ \ul{1}   & \ul{1} &= \ul{5} - 2\cdot \ul{2} = 5\cdot \ul{101} - 42\cdot \ul{12}.
\end{align*}
Thus $x=-42$, $y=5$ works, and $\gcd(a,b)=1$.

We can use the result of this computation to solve 
$$12x\con 1\pmod{101}.$$
Indeed, $1=(-42)\cdot 12 + 5\cdot 101$, so 
$x=-42$ is a solution.
\end{example}

\subsection{Powering Algorithm}
There is a clever trick that makes computing $a^n$ easier.
Write $n$ in binary, that is is write $n=\sum_{i=0}^r \eps_i 2^i$ 
with $\eps_i \in \{0,1\}$.
Then 
$$a^n \,\,=\, \prod_{\text{$i$ with }\eps_i\neq 0} a^{2^i}.$$

\subsection{PARI}
The midterm will {\bf NOT} test knowledge of PARI.


