Cryptography PDF
Cryptography PDF
CRYPTOGRAPHY
Allison Mackay
CONTENTS
1. Rudiments of number theory
2. Euler’s Phi function
3. Classical cryptosystems and one time pad
4. Modular exponentiation
5. The RSA cryptosystem
x+ y = y+x x⋅ y = y⋅x
x + ( y + z) = ( x + y) + z x ⋅( y ⋅ z) = ( x ⋅ y)⋅ z
x + (−x) = 0 x ⋅1 = x
x+0= x x ⋅( y + z) = x ⋅ y + x ⋅ z
Examples
In 2 = {0,1} we have 1 + 1 = 0 and ( x + y ) = x 2 + y 2
2
Examples
−1
3∈ 14 is invertible and 3 =5
−1
7∈ 19 is invertible and 7 = 11
2∈ 4 is not invertible.
Finding inverses in n
d = gcd ( a, b ) ⇒ ∃x∃y ( d = ax + by )
Example:
a = 37, b = 29 ⇒ d = gcd ( a, b ) = 1,
x = 11, y = −14
1 = 37 ⋅11 + 29 ⋅ ( −14 )
Example
φ (10 ) = 4 , because the invertible elements in 10 are
precisely 1, 3,7,9 .
Equivalently
φ ( n ) = #{ x = 0,..., n − 1| gcd ( x, n ) = 1}
⎛ 1 ⎞⎛ 1 ⎞ ⎛ 1 ⎞
THEOREM φ ( n ) = n ⎜ 1 − ⎟⎜ 1 − ⎟ ...⎜1 − ⎟
⎝ p1 ⎠⎝ p2 ⎠ ⎝ pk ⎠
where p1 , p2 ,..., pk are all prime factors of n .
⎛ 1 ⎞⎛ 1⎞
Example: φ (10) = 10 ⎜1 − 2 ⎟⎜1 − 5 ⎟ = 4
⎝ ⎠⎝ ⎠
PROOF. We want to count the number of elements
x ∈ {0,1,..., n − 1} satisfying the gcd ( x, n ) = 1.
Note that the condition gcd ( k , n ) = 1is equivalent to
p1 | x,..., pk | x
Let Ai be the set of elements x ∈ {0,1,..., n − 1} with pi | x .
Then the union A1 ∪ A2 ∪ ... ∪ Ak represents the set of all
elements x ∈ {0,1,..., n − 1} which are divisible by at least
one of the primes p1 ,..., pk , that is, which are NOT
relatively prime to n . By the inclusion-exclusion principle
A1 ∪ ... ∪ Ak = ∑ Ai − ∑ Ai ∩ Aj +
i i< j
+ ∑ Ai ∩ Aj ∩ Al + .... + ( −1)
k −1
A1 ∩ A2 ∩ ... ∩ Ak =
i < j <l
n n n n
=∑ −∑ +∑ + ... + ( −1)
n −1
=
i pi i< j pi p j i < j <l pi p j pl p1 p2 ... pk
⎡ ⎛ 1 ⎞⎛ 1 ⎞ ⎛ 1 ⎞⎤
= n ⎢1 − ⎜ 1 − ⎟⎜ 1 − ⎟ ...⎜ 1 − ⎟ ⎥
⎣ ⎝ p1 ⎠⎝ p2 ⎠ ⎝ pk ⎠ ⎦
Therefore
⎛ 1 ⎞⎛ 1 ⎞ ⎛ 1 ⎞
φ ( n ) = n − A1 ∪ ... ∪ Ak = n ⎜1 − ⎟⎜1 − ⎟ ...⎜1 − ⎟
⎝ p1 ⎠⎝ p2 ⎠ ⎝ pk ⎠
SPECIAL CASE
Then
⎛ 1 ⎞⎛ 1 ⎞ p −1 q −1
φ ( n ) = n ⎜1 − ⎟⎜ 1 − ⎟ = pq ( )( ) = ( p − 1)( q − 1)
⎝ p ⎠⎝ q ⎠ p q
Indeed, since
φ ( n ) = ( p − 1)( q − 1) = pq + 1 − ( p + q ) = n + 1 − ( p + q ) ,
it follows that p + q = n + 1 − φ ( n ) . Once we know the
product pq = n and the sum p + q = n + 1 − φ ( n ) , the
primes p, q can be determined by solving a quadratic
equation, x 2 − ( n + 1 − φ ( n ) ) x + n = 0 .
EULER’S THEOREM
φ(n)
a = 1 in n
THE ALPHABET
A B C D E F G H I J K L M N O
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
P Q R S T U V W X Y Z
15 16 17 18 19 20 21 22 23 24 25
ax + b = y ⇒ ax = y − b ⇒ a −1 ( ax ) = a −1 ( y − b ) ⇒ x = a −1 y − a −1b
f −1 : n → n , f −1 ( x ) = a −1 x − a −1b
“DR TC DR XC YH VE”
↓
Encryption with Key
↓
Numerical Code
↓
Encrypted Message
∑ ( letter ) ⋅ 26 ∈ {0,1,..., 26
i =0
i
i k
− 1}
For example: The quadruple “four” would be
encrypted by:
r (260 ) + u (261 ) + o(262 ) + f (263 ) =
17(1) + 20(26) + 14(676) + 5(17576) = 97871∈ 264
iybvexpdtqqusyjiibejzrcdpunmukmawzfanqrxgdzvelqsyazk
unwkqkxzwsnyiijgqwxocygtnnusmzasncbmhvpcgkkutiamf
tyyoegnvlrjkzarkxtuwufuszsebmthhgwfoduobtiuvdvzmkmo
eznrlhljqglumzpfnfivkvukwadbekfktyirkeqkdgyhfrnmirfog
ghvonfgzfvbyrhbimgzwyaukvmkeychvidvkfnycbjuzxxvpfl
skeqqbdloiralavaicjawqsyzmylyzjiadnpgwofhakhibgiyoyxz
bzvhcxhonqfsasbbdscbvamyxjkrafyeotephcovvlrqzjcaxvas
olyoejvcswfdxfcqauvktnceddibzkexilmcwrvhbkfvnjmnnfyk
uzmjssvgadhemycqdduiujueqjxnkvhhfocqlmovutqbqyawdk
kksgrfnqpldtcwchsgvtbbzrvayqhkfpdvlmzqrycmkxurwaupi
vujnqelysqxyoazblxnoetvrlaidhkbqwkehtjaiqveailyzzglmiw
doibgvdvkzrhckcazxqicpltiuxnrquigmuqszjfiypgviaevcbtqo
irvxypzllyvphnrhjzqqnmkgfuebtbmmgqlgjpzwedpxgvwwjc
teoixgchjxzgiaimitdezrtxmwbprhbyqaxmwztwsnfkotkaggo
pbmdrmcqcwpveybqwnchpeobvfdzqtssgshulbmrxfzbzpuoz
rptxcatqadjzfcmrhalzhzvhswylkwsgsmmirgxmqhrdyvgrzoz
yibbekpbofnequaupyrarqtjzsmvesjhjvrtsbcthhkmbnlyqcmb
exsdkztswvlgrehuijymdmysjbdtmkqngypfzrtkypatcnxjexjtj
mzigjuujobljtezrxjkkkjbdznxdvbedvobjhonczluqwqygjblqc
opbfgycfopakugokecpoo
4. MODULAR EXPONENTIATION
⎛
( ) ( ) ⎞⎟⎠ ,
⎞ , a 22 = ⎛ a 21
2 2
a = a, a = ⎜ a
20 21
20
⎟ ⎜
⎝ ⎠ ⎝
( ) = ⎛⎜ ( a ) ⎞⎟
Calculate ,
⎛
a =⎜ a
23 22 ⎞ ,..., a 2t
2
2t −1
2
⎟
⎝ ⎠ ⎝ ⎠
t
where 2 is the largest power of 2 that is less than or equal to K .
N = pq
The large number N will be made public.
• Next she calculatesφ ( N ) = ( p − 1)( q − 1) and keeps
φ ( N ) for herself.
• She then picks up an integer e which is
invertible mod φ ( N ) . The number e will be made
public. This will be Alice’s public encryption key. In a
public directory everybody could see the numbers e
and N .
• Finally she uses the Extended Euclidean Algorithm to
calculate the inverse d = e −1 mod φ ( N ) . This will
be the private decryption key for Alice.
Now assume that Bob wants to send Alice a message.
We will assume the message is represented by an element
x ∈ N (if the message is large, Bob will break it into
pieces, each piece of the message being represented as an
element of N ).
function otpencrypt=otpencrypt(x,onetime)
y=strcode(x);
n=size(y,2);
for I=1:n;
z(I)=mod(y(I)+onetime(I),26);
end
for I=1:n;
w(I)=codel(z(I));
end
otpencrypt=w
function otpdecrypt=otpdecrypt(x,onetime)
y=strcode(x);
n=size(y,2);
for I=1:n;
z(I)=mod(y(I)-onetime(I),26);
end
for I=1:n;
w(I)=codel(z(I));
end
otpdecrypt=w
REFERENCES