update typo and structures

This commit is contained in:
Trance-0
2024-12-16 13:41:24 -06:00
parent ce830c9943
commit d471db49c4
24 changed files with 328 additions and 219 deletions

View File

@@ -1,42 +1,42 @@
# Lecture 1
> I changed all the element in set to lowercase letters. I don't know why K is capitalized.
## Chapter 1: Introduction
## Alice sending information to Bob
### Alice sending information to Bob
Assuming _Eve_ can always listen
Rule 1. Message, Encryption to Code and Decryption to original Message.
## Kerckhoffs' principle
### Kerckhoffs' principle
It states that the security of a cryptographic system shouldn't rely on the secrecy of the algorithm (Assuming Eve knows how everything works.)
**Security is due to the security of the key.**
## Private key encryption scheme
### Private key encryption scheme
Let $\mathcal{M}$ be the set of message that Alice will send to Bob. (The message space) "plaintext"
Let $M$ be the set of message that Alice will send to Bob. (The message space) "plaintext"
Let $\mathcal{K}$ be the set of key that will ever be used. (The key space)
Let $K$ be the set of key that will ever be used. (The key space)
$Gen$ be the key generation algorithm.
$k\gets Gen(\mathcal{K})$
$k\gets Gen(K)$
$c\gets Enc_k(m)$ denotes cipher encryption.
$m'\gets Dec_k(c')$ $m'$ might be null for incorrect $c'$.
$Pr[K\gets \mathcal{K}:Dec_k(Enc_k(M))=m]=1$ The probability of decryption of encrypted message is original message is 1.
$P[k\gets K:Dec_k(Enc_k(M))=m]=1$ The probability of decryption of encrypted message is original message is 1.
*_in some cases we can allow the probailty not be 1_
*_in some cases we can allow the probability not be 1_
## Some examples of crypto system
### Some examples of crypto system
Let $\mathcal{M}=$ {all five letter strings}.
Let $M=\text{all five letter strings}$.
And $\mathcal{K}=$ {1-$10^{10}$}
And $K=[1,10^{10}]$
Example:
@@ -48,13 +48,13 @@ $Dec_{1234567890}(brion1234567890)="brion"$
Seems not very secure but valid crypto system.
## Early attempts for crypto system.
### Early attempts for crypto system
### Caesar cipher
#### Caesar cipher
$\mathcal{M}=$ finite string of texts
$M=\text{finite string of texts}$
$\mathcal{K}=$ {1-26}
$K=[1,26]$
$Enc_k=[(i+K)\% 26\ for\ i \in m]=c$
@@ -68,11 +68,11 @@ def caesar_cipher_dec(s: str, k:int):
return ''.join([chr((ord(i)-ord('a')+26-k)%26+ord('a')) for i in s])
```
### Substitution cipher
#### Substitution cipher
$\mathcal{M}=$ finite string of texts
$M=\text{finite string of texts}$
$\mathcal{K}=$ bijective linear transformations (for English alphabet, $|\mathcal{K}|=26!$)
$K=\text{set of all bijective linear transformations (for English alphabet},|K|=26!\text{)}$
$Enc_k=[iK\ for\ i \in m]=c$
@@ -80,11 +80,11 @@ $Dec_k=[iK^{-1}\ for\ i \in c]$
Fails to frequency analysis
### Vigenere Cipher
#### Vigenere Cipher
$\mathcal{M}=$ finite string of texts
$M=\text{finite string of texts with length }m$
$\mathcal{K}=$ key phrase of a fixed length
$K=\text{[0,26]}^n$ (assuming English alphabet)
```python
def viginere_cipher_enc(s: str, k: List[int]):
@@ -106,6 +106,22 @@ def viginere_cipher_dec(s: str, k: List[int]):
return res
```
### One time pad
#### One time pad
Completely random string, sufficiently long.
Completely random string, sufficiently long.
$M=\text{finite string of texts with length }n$
$K=\text{[0,26]}^n$ (assuming English alphabet)$
$Enc_k=m\oplus k$
$Dec_k=c\oplus k$
```python
def one_time_pad_enc(s: str, k: List[int]):
return ''.join([chr((ord(i)-ord('a')+k[j])%26+ord('a')) for j,i in enumerate(s)])
def one_time_pad_dec(s: str, k: List[int]):
return ''.join([chr((ord(i)-ord('a')+26-k[j])%26+ord('a')) for j,i in enumerate(s)])
```