Cryptography and Computer Security

« nazaj

Cryptography and computer security - Tutorial 6.10.2020


Modular arithmetic

\[\begin{aligned} a \equiv b \pmod{n} &\Leftrightarrow \exists k \in \mathbb{Z}: a - b = kn \\ a \bmod{n} &= \text{the remainder when dividing $a$ by $n$} \\ a \bmod{n} = b &\Leftrightarrow a \equiv b \pmod{n} \ \land \ 0 \le b \le n-1 \\ a \equiv b \pmod{n} &\Leftrightarrow a \bmod{n} = b \bmod{n} \end{aligned}\]

Exercise 1

Evaluate $2020 \bmod{13}$ and $(-2020) \bmod{13}$.

  2020 / 13 = 155
- 13
   72
-  65
    70
-   65
     5

Exercise 2

Solve $x + 4 \equiv 2 \pmod{7}$ and $3x - 4 \equiv 4 \pmod{7}$.

\[\begin{aligned} x + 4 &\equiv 2 \pmod{7} \\ \exists k \in \mathbb{Z}: x + 4 - 2 &= 7k \\ \exists k \in \mathbb{Z}: x - (-2) &= 7k \\ x &\equiv -2 \pmod{7} \end{aligned}\] \[\begin{aligned} 3x - 4 &\equiv 4 \pmod{7} \\ 3x &\equiv 8 \pmod{7} \\ 3x &\equiv 1 \pmod{7} \\ \exists k \in \mathbb{Z}: 3x - 1 &= 7k \\ \exists k \in \mathbb{Z}: 3x &= 7k + 1 & k = 2 + 3t &\quad (k \equiv 2 \pmod{3}) \\ \exists t \in \mathbb{Z}: 3x &= 7(2 + 3t) + 1 \\ \exists t \in \mathbb{Z}: 3x &= 15 + 21t \\ \exists t \in \mathbb{Z}: x &= 5 + 7t \\ \exists t \in \mathbb{Z}: x - 5 &= 7t \\ x &\equiv 5 \pmod{7} \end{aligned}\]

$3 \bot 7$$3$ and $7$ are coprime ($\gcd(3, 7) = 1$)


Exercise 3

List all the invertible elements in $\mathbb{Z}_{26}$ and determine their inverses.

\[\begin{aligned} 1^{-1} &\equiv 1 \pmod{26} & 25^{-1} &\equiv 25 \pmod{26} \\ 3^{-1} &\equiv 9 \pmod{26} & 23^{-1} &\equiv 17 \pmod{26} \\ 9^{-1} &\equiv 3 \pmod{26} & 17^{-1} &\equiv 23 \pmod{26} \\ 5^{-1} &\equiv 21 \pmod{26} & 21^{-1} &\equiv 5 \pmod{26} \\ 7^{-1} &\equiv 15 \pmod{26} & 19^{-1} &\equiv 11 \pmod{26} \\ 15^{-1} &\equiv 7 \pmod{26} & 11^{-1} &\equiv 19 \pmod{26} \end{aligned}\]

Exercise 4

Prove that $a \bmod{n} = b \bmod{n}$ if and only if $a \equiv b \pmod{n}$.


Classical ciphers

Cryptosystem: $(\mathcal{P}, \mathcal{C}, \mathcal{K}, \mathcal{E}, \mathcal{D})$

Caesar cipher:

Substitution cipher:

Exercise 5

If an encryption function $E_k$ is identical to the decryption function $D_k$, then the key $k$ is said to be an involutory key. Find all involutory keys for the Caesar cipher over $\mathbb{Z}_{26}$.

\[\begin{aligned} k &\equiv -k \pmod{26} \\ 2k &\equiv 0 \pmod{26} \\ k &\equiv 0 \pmod{13} \\ k &\in \{0, 13\} \end{aligned}\]

Exercise 6

An affine cipher has $E_k(x) = 5x+1 \bmod{26}$ as its encryption function. What is its decryption function?

Affine cipher:


Exercise 7

Suppose that $k = (a, b)$ is a key for the affine cipher over $\mathbb{Z}_n$. Prove that $k$ is involutory if and only if $a^{-1} \bmod{n} = a$ and $b(a+1) \equiv 0 \pmod{n}$.


Exercise 8

Determine all involutory keys for the affine cipher over $\mathbb{Z}_{26}$.


Exercise 9

Is it possible that an affine cipher over $\mathbb{Z}_{26}$ encrypts H to N and I to R?


Exercise 10

Decrypt the following ciphertext, which has been obtained from a substitution cipher, with word division preserved. Help yourself with this website.

YI QCLJMXNCTJEL, T QTFPTC QYJEFC YP XIF XW MEF PYBJUFPM TIO BXPM
DYOFUL ZIXDI FIQCLJMYXI MFQEIYGAFP. YM YP T MLJF XW PASPMYMAMYXI
QYJEFC YI DEYQE FTQE UFMMFC YI MEF JUTYIMFKM YP CFJUTQFO SL
T UFMMFC PXBF WYKFO IABSFC XW JXPYMYXIP OXDI MEF TUJETSFM.