You are on page 1of 7

Các dạng bài thi CRY303c

1)Find mod with know totient


y qm+r qm+ ymod m
x =x =x
y qm y mod m
x =x x
m q y mod m
x =( x ) x
y

q
x y ≡ ( x m ) x y mod φ(N ) (mod N )

y q ymod φ ( N )
x ≡1 x ( mod N ) IF gcd ( x , N )=1

Q1(file đề)
Cách làm
Euler’s Theorem: If n ≥ 1 and GCD(a,n) = 1 then a^totient(n) ≡ 1(mod n)

totient(527) =480
526^959 mod 527 = ((526^480)^2 * 526^-1) mod 527
= (( (526^480)^2 mod 527 )*( 526^-1 mod 527)) mod 527
= (1*526) mod 527 = 526

- Trình bày như trên là có điểm còn cách tính 526^-1 mod 527 ( Phần
kiến thức tìm nghịch đảo modulo ) thì tham khảo cách tính tại video này
trên youtube:
https://www.youtube.com/watch?v=oFtVYP9sDxE

2)Một số thuật toán mã hóa


***Thay thế (Substitution cipher) ( Caeser Cipher )
- Mã hóa thay thế là thay từng kí tự chữ cái trong đoạn text thành một chữ
cái khác trong bảng chữ cái alphabet theo key ( quy luật sinh key ứng với
từng kiểu mã hóa)

* Caeser Cipher
- Formula Decrypt : p = ( x-k ) mod 26
- Formula Encrypt : c = ( x+k ) mod 26

You agreed to use a Caesar cipher with a key of k=5 with a friend. While sitting in a
group, the friend hands you over a message that says "QNGWFWD". Decrypt the
message.
- The English alphabet:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
- Caesar cipher decrypt with a key k = 5:
Formula: p = ( x-k ) mod 26

Q = (16-5) mod 26 = 11 ---> L


N = (13-5) mod 26 = 8 ----> I
G = (6-5) mod 26 = 1 ---> B
W = (22-5) mod 26 = 17 ---> R
F = (5-5) mod 26 = 0 ---> A
W = (22-5 ) mod 26 = 17 ---> R
D = (3-5) mod 26 = 24 ---> Y
----> The plain text of QNGWFWD is LIBRARY

***Chuyển vị (Transposition Cipher) ( Permutation


Cipher ,Vigenere Cipher )

* Permutation Cipher

- Dạng 1: The plaintext MEETMELATER gets processed by a


Permutation Cipher (with a key of [2 3 5 4 1] and no padding with
extra letters. What is the corresponding ciphertext?
- Đọc đề bài có key = [2 3 5 4 1] ==> Bảng có 5 cột ==> Sau đó lần lượt
viết từng chữ cái của text theo thứ tự từ trái sang phải và điền vào bảng
M E E T M
E L A T E
R
- Theo thứ tự các cột được in ra của key ta có MEMERELTTEA
(ciphertext)

- Dạng 2: The plaintext MEETMELATER gets processed by a


Permutation Cipher (with a key of [2 3 5 4 1] and with padding using
the letter "z" (Alice and Bob agree to use the letter z for padding). What
is the corresponding ciphertext?
- Vẫn làm như dạng 1 nhưng chú ý những ô trống thừa trong bảng sẽ điền
kí tự được padding vào (ở đây cụ thể là chữ z)
M E E T M
E L A T E
R Z Z Z Z
===> Ciphertext : MEZMERELZTTZEAZ

* Rail Fence cipher 


The Rail Fence cipher uses 4 rows/rails . What is the ciphertext (the
outcome of the rail fence cipher) for MEETMELATER?
- Đọc đề bài có key = 4 ===> Có 4 dòng ==> Sau đó lần lượt viết từng
chữ cái của text từ trên xuống dưới hết 4 dòng rồi tiếp tục từ dưới lên
trên.
M L ML
E E A ---> EEA ---> MLEEAEMTRTE
E M T R EMTR (ciphertext)
T E TE

* Vigenere
Decrypt the message (DTXSAOMP) using the Vigenere cipher with the
key LEMON.
Key = LEMON ===> m = 5
Encryption: Ci = (Pi + Ki mod m) mod 26

Plaintext: MEET ME LATER


(Right-Shift by:) LEMO NL EMONL
Ciphertext: XIQH ZP PMHRC

Decryption: Pi = (Ci - Ki mod m) mod 26

Ciphertext: XIQH ZP PMHRC


(Left-Shift by:) LEMO NL EMONL
Plaintext: MEET ME LATER

3)Forgot the key (Caesar cipher)


- Because the formula of decryption Caesar cipher is:
c = (x -k) mod 26
---> If forgot the key, after 26 times rotated the text will come right back
to the original.

4)Euler totient function (file đề Q5)


- Dấu hiệu nhận biết : cho keyword như trên và đoạn text “between 1 and
n-1”
- Cách làm :
Phân tích số mà đề bài đã cho thành tích của các thừa số nguyên tố
8 = 2^3
- Sau đó tính totient của n (ở bài này là 8) :
totient(n) = n*(1-1/(số nguyên tố sau khi đã phân tích thứ nhất))*(1-1/(số
nguyên tố sau khi đã phân tích thứ hai))

* Lưu ý: Nếu có thêm nguyên tố sau khi phân tích thì cứ tiếp tục nhân
thêm với (1 trừ 1/số nguyên tố đó) .
---> totient(8) = 8*(1-1/2) = 4

5)Cũng là Euler totient function (file đề Q6)


- Dấu hiệu nhận biết :
+ Có keyword bên trên trong đề bài
+ Cho biết 3 giá trị p,q,e
+ Có đoạn text “n is the modulus of RSA cipher”
- Cách làm :
+ Bước 1: Liệt kê các thông số của đề bài cho
p = 7 , q=11 , e=17
+ Bước 2: Tính n:
n=p*q=7*11 = 77
+ Bước 3: Tính phi (n):
Totient (77) = (p-1)*(q-1) = 6 * 10 = 60

6)The Extended Euclidean algorithm


- Formula of Extended Euclidean algorithm:
Encryption: C = M^e mod n
Decryption: M = C^d mod n

- Đề bài:
 Using the same notations as in the lecture, e.g., p and q are the two
primes and e and d are the public key and the private key, respectively,
p=7, q=11, e=17. Using the phi(n) that you found in the previous question
and the Extended Euclidean algorithm yields d=53. What is the ciphertext
C when encrypting M=8?

- Cách làm:
p=7 , q=11 , e=17 , d=53 , M=8
---> n = 7*11 = 77
---> totient(77) = (p-1)*(q-1) = 6*10 = 60
- Formula of Extended Euclidean algorithm:
Encryption: C = M^e mod n
---> C = 8^17 mod 77
= (8^8 * 8^8 * 8) mod 77
= ((8^8 mod 77) * (8^8 mod 77) * (8 mod 77)) mod 77
= (71 * 71 * 8) mod 77
= 57

7)Chosen Ciphertext Attacks


Formular: Chooses c’ = c * r^e (mod n) for some r
=== > m’ = m * r (mod n)

Using the same notations as in the lecture, e.g., p and q are the two
primes and e and d are the public key and the private key, respectively,
p=3, q=11, and e=7.The attacker performs a chosen-ciphertext attack
(CCA). It has a known ciphertext 14 and wants to retrieve the
corresponding plaintext. It computes c' = c * r^e mod n and chooses
the ciphertext 14 * 2187 mod 33 = 27 and retrieves the corresponding
plaintext, 15. What is the plaintext corresponding to the ciphertext 14?

- Cách làm
p=3 , q=11 , e=7 , C=14 , m’ = 15
n = p*q = 3*11 = 33
c’ = c*r^e mod n choose the ciphertext 14*2187 mod 33 = 27
---> r =√7 2187 = 3
m’ = m*r mod n ---> 15 = m*3 mod 33 --->m = 5

8)Diffie-Hellman Key Exchange ( file đề Q9 )


- Đầu tiên đọc đề bài bắt được keyword trên thì liệt kê ra các thành phần
cần ( tóm tắt đề bài ) rồi đem áp dụng công thức bên dưới . Sẽ đi tìm giá
trị của 1 biến trong biểu thức bên dưới.( Chú ý là Alice send cho Bob hay
Bob send cho Alice )

Alice and Bob uses Diffie-Hellman Key Exchange to share a key with a
common prime p=11 and a primitive root a=2. If Alice has a public key
Y_A=9, what is her private key X_A?

Y_A=9 , a=2 , p=11


- Use formula Diffie-Hellman Key Exchange:
Y_A = a^X_A mod p
9 = 2^X_A mod 11
---> X_A = 6

(This question builds on the previous question.) Alice and Bob uses
Diffie-Hellman Key Exchange to share a key with a common prime p=11
and a primitive root a=2. If Bob has a public key Y_B=3, what is the
secret key K shared with Alice?
- Câu này ban đầu sẽ giải như câu trên để tìm ra giá trị của X_A rồi sau
đó sẽ làm tiếp như bên dưới.
Y_B=3 , a=2 , p=11
- Use formula Diffie-Hellman Key Exchange:
K = Y_B^X_A mod p
K = 3^6 mod 11
---> K = 3
3 (3^6 mod 11 = 3 computed by Alice)

9)Compute key exchange session

- Dấu hiệu nhận biết :


+ Dạng 1:
There are 5 computers (hardware. Each computer hosts 4 virtual
machines (VM) with different addresses, and each VM hosts 10
applications. How many key exchange sessions (in one session, two
logical parties share a key) are needed if the decentralized key
distribution is used so that all VM's share a pair-wise keys?

+ Dạng 2:
(This problem has the same setup as the previous question but asks a
different question.) There are 5 computers (hardware. Each computer
hosts 4 virtual machines (VM) with different addresses, and each VM
hosts 10 applications. How many key exchange sessions (in one session,
two logical parties share a key) are needed if the decentralized key
distribution is used so that all applications share a pair-wise keys?

- Cách làm:
+ Dạng 1:
- Suppose n is called as the number of all VM’s.
- Because there are 5 computers (hardware), each computer hosts 4
virtual machines (VM) with different addresses:
---> n = 5*4 = 20 (VM’s)
---> We need (n*(n-1))/2 keys for n VM’s = (20*19)/2 = 190 key
exchange sessions

+ Dạng 2:
- Suppose n is called as the number of all VM’s.
- Because there are 5 computers (hardware), each computer hosts 4
virtual machines (VM) with different addresses and each VM hosts 10
applications:
---> n = 5*4 * 10 = 200 (VM’s)
---> We need (n*(n-1))/2 keys for n VM’s = (200*199)/2 = 19900 key
exchange sessions

You might also like