This shows you the differences between two versions of the page.
ic:labs:02 [2021/01/25 11:03] razvan.smadu |
ic:labs:02 [2023/10/09 19:15] (current) razvan.smadu |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Laboratorul 02 - Shift and Vigenère Ciphers ===== | ===== Laboratorul 02 - Shift and Vigenère Ciphers ===== | ||
- | The powerpoint presentation for this lab can be found [[https://drive.google.com/file/d/1rbiXVtSESTDc2rAyaO9oNRNLE3NRw54a/view?usp=sharing|here]]. | + | Prezentarea PowerPoint pentru acest laborator poate fi găsită [[https://drive.google.com/file/d/1rbiXVtSESTDc2rAyaO9oNRNLE3NRw54a/view?usp=sharing|aici]]. |
- | Please download the lab skeleton from here: {{:ic:res:lab2_sketch.zip|}} | + | Puteți lucra acest laborator folosind platforma Google Colab, accesând [[https://colab.research.google.com/github/ACS-IC-labs/IC-labs/blob/main/labs/lab02/lab2.ipynb|acest]] link. |
- | The archive contains the following: | + | |
- | * **format_funcs.py**: the format functions from the previous lab; | + | |
- | * **caesar.py**: the implementation of the Caesar encryption and decryption from the previous lab; | + | |
- | * **msg_ex1.txt**: the text which needs to be decrypted for exercise 1; | + | |
- | * **msg_ex2.txt**: the text which needs to be decrypted for exercise 2; | + | |
- | * **msg_ex3.txt**: the text which needs to be decrypted for exercise 3; | + | |
- | * **ex1.py**: implementation of exercise 1; | + | |
- | * **ex2.py**: implementation of exercise 2; | + | |
- | * **ex3.py**: implementation of exercise 3. | + | |
- | You need to fill in the TODOs from **ex1.py**, **ex2.py**, and **ex3.py**. | + | <hidden> |
+ | Pentru acest laborator, vom avea nevoie de scheletul de cod care se găsește aici: {{:ic:res:lab2_sketch.zip|}}. | ||
- | ==== Exercise 1 (2p) ==== | + | Conținutul arhivei: |
+ | * **utils.py**: funcțiile de formatare din laboratorul anterior; | ||
+ | * **caesar.py**: implementarea funcțiilor de criptare și decriptare folosind Cifrul Cezar, din laboratorul anterior; | ||
+ | * **msg_ex1.txt**: textele care trebuie decriptate pentru exercițiul 1; | ||
+ | * **msg_ex2.txt**: textele care trebuie decriptate pentru exercițiul 2; | ||
+ | * **msg_ex3.txt**: textele care trebuie decriptate pentru exercițiul 3; | ||
+ | * **ex1.py**: scheletul de cod pentru exercițiul 1; | ||
+ | * **ex2.py**: scheletul de cod pentru exercițiul 2; | ||
+ | * **ex3.py**: scheletul de cod pentru exercițiul 3. | ||
- | Alice sends Bob the following ciphertexts: | + | Va trebui să completați cu soluțiile voastre acolo unde apare TODO, în fișierele **ex1.py**, **ex2.py**, și **ex3.py**. |
+ | |||
+ | ==== Exercițiul 1 (2p) ==== | ||
+ | |||
+ | Alice îi trimite lui Bob următoarele ciphertexte: | ||
<code> | <code> | ||
LDPWKHORUGBRXUJRG | LDPWKHORUGBRXUJRG | ||
Line 33: | Line 37: | ||
</code> | </code> | ||
- | Charlie manages to capture the ciphertexts and he finds that the cipher used for | + | Charlie reușește să intercepteze ciphertextele și își dă seama că cifrul folosit pentru criptare este Shift Cipher (fiecare mesaj posibil criptat cu o cheie diferită). Puteți decripta mesajele? |
- | encryption is the shift cipher (each message possibly encrypted with a different | + | |
- | key). Can you decrypt the messages? | + | |
- | Charlie also knows that the plaintext consists only of the English letters A to | + | Charlie știe de asemenea ca plaintextul este în limba engleză și constă în litere ale alfabetului englez (A-Z), numai majusculă și fără semne de punctuație. |
- | Z (all capitals, no punctuation). | + | |
- | <note tip>**Hint:** What do all the plain texts have in common? The answer is YOU.</note> | + | <note tip>**Hint:** Ce au în comun toate textele în clar? Răspunsul este YOU.</note> |
- | It seems like the 5th string is different. Can you find a way to decrypt it too? | + | Se pare că al cincilea string este diferit. Puteți să găsiți o modalitate de a-l decripta? |
- | ==== Exercise 2 (4p) ==== | + | ==== Exercițiul 2 (4p) ==== |
- | Alice sends Bob another ciphertext, but much longer this time... | + | Alice îi trimite lui Bob un alt ciphertext, dar mai lung de această dată... |
- | {{:ic:res:msg_ex2.txt|Download message file}} | + | {{:ic:res:msg_ex2.txt|Descărcați mesajul}} |
- | Charlie needs to decrypt this as well. Some colleagues tell him this is encrypted | + | Charlie trebuie de asemenea să decripteze acest mesaj. Unii colegi i-au spus că este criptat folosind cifrul substituției (engl. substitution cipher), și din nou textele în clar constau doar în litere ale alfabetului englez de la **A** la **Z** (toate majusculă, fără punctuație). Încercați să-l ajutați pe Charlie să decripteze acest mesaj. |
- | using the substitution cipher, and that again the plaintext consists only of the English letters **A** to **Z** (all capitals, no punctuation). Try to help Charlie to decrypt this. | + | |
+ | **Hint**: Folosiți mecanismul analizei bazate pe frecvența literelor, care a fost discutată la curs. Vedeți că frecvența fiecărei litere nu se mapează precis. Cu alte cuvinte, cele mai frecvente două litere se potrivesc cu tabelul dat la curs, dar altele sunt amestecate. Cu toate acestea, Charlie știe că cele mai frecvente bi-grame sunt următoarele (de la cel mai frecvent la cel mai puțin frecvent): | ||
- | **Hint:** use the frequency analysis mechanisms we discussed in class. Note that the frequency of each letter does not map precisely. In particular, the most frequent two letters do match well with the given table, but the others are sometimes mixed. However, Charlie knows that the most frequent bi-grams are the following (from most frequent to less frequent): | ||
**TH**, **HE**, **IN**, **OR**, **HA**, **ET**, **AN**, **EA**, **IS**, **OU**, **HI**, **ER**, **ST**, **RE**, **ND** | **TH**, **HE**, **IN**, **OR**, **HA**, **ET**, **AN**, **EA**, **IS**, **OU**, **HI**, **ER**, **ST**, **RE**, **ND** | ||
- | With this information, can you tell what the ciphertext is about? | + | Folosind această informație, puteți spune despre ce este vorba în textul cifrat? |
+ | |||
+ | <note tip>**Hint:** Puteți folosi **sort_dictionary** care deja este definit în scheletul laboratorului.</note> | ||
- | <note tip>**Hint:** You can use the **sort_dictionary** which is already defined in the skeleton file.</note> | + | ==== Exercițiul 3 (4p) ==== |
- | ==== Exercise 3 (4p) ==== | + | |
- | Charlie manages to capture {{:ic:res:msg_ex3.txt|a last communication}} which turns out to be the most important, so it is crucial he decrypts it. However, this time Alice used the Vigenere cipher, with a key that Charlie knows has **7** characters. | + | Charlie reușește să intercepteze {{:ic:res:msg_ex3.txt|o ultimă comunicație}} care se pare a fi cea mai importantă, deci este decisiv ca el să o decripteze. Cu toate acestea, de data aceasta Alice a folosit cifrul Vigenere, cu o cheie despre care Charlie știe ca are **7** caractere. |
- | The ciphertext is in the file attached. Try the method of multiplying probabilities as explained in class and see if you can decrypt the ciphertext. You can find details about this method [[http://www.cs.mtu.edu/~shene/NSF-4/Tutorial/VIG/Vig-Recover.html|here]]. | + | Ciphertextul este în fișierul atașat. Încercați metoda multiplicării probabilitătilor așa cum a fost explicat la curs și vedeți dacă puteți decripta ciphertextul. Puteți găsi mai multe detalii despre această metodă [[http://www.cs.mtu.edu/~shene/NSF-4/Tutorial/VIG/Vig-Recover.html|aici]]. |
- | These are the known frequencies of the plaintext: | + | Acestea sunt frecvențele cunoscute ale textului în clar: |
<code> | <code> | ||
Line 96: | Line 98: | ||
</code> | </code> | ||
- | ==== Bonus: Exercise 4 (2p) ==== | + | ==== Bonus: Exercițiul 4 (2p) ==== |
- | In class, we explained that the One Time Pad is malleable (i.e. we can easily change the encrypted plaintext by simply modifying the ciphertext). We have also discussed how the CRC was a very bad idea in the design of WEP due to its linearity. | + | La curs am spus că One Time Pad este maleabil (i.e. putem schimba cu ușurință criptarea unui text în clar prin simpla schimbare a ciphertextului). De asemenea, am discutat cum CRC este o idee proastă de design pentru protocolul WEP, din cauza proprietății de linearitate. |
- | You are given the following ciphertext in hexadecimal: | + | Vi se dă următorul ciphertext, în hexazecimal: |
<code> | <code> | ||
021e0e061d1694c9 | 021e0e061d1694c9 | ||
</code> | </code> | ||
- | which you know it corresponds to the concatenation of the message "floare" with its CRC-16 (in hexa "8E31") obtained from this website: | + | care corespunde concatenării mesajelor "floare" și CRC-16 asociat mesajului (în hexa este "8E31") obținut folosind acest website: |
http://www.lammertbies.nl/comm/info/crc-calculation.html | http://www.lammertbies.nl/comm/info/crc-calculation.html | ||
- | If we need to modify the ciphertext so that a correct decryption outputs "albina" instead of "floare" and such that the CRC-16 calculation remains correct, what is the modification we need to perform? | + | Dacă trebuie să modificăm ciphertextul astfel încât o decriptare corectă să ducă la "albina" în loc de "floare", iar calcularea CRC-16 să rămână corectă, care este modificarea pe care trebuie să o realizăm? |
- | Output the new ciphertext after the necessary modifications and show that it correctly leads to the plaintext "albina" and a correct computation of its CRC-16. | + | Afișați noul ciphertext după modificările necesare, și arătați că în mod corect duce la plaintextul "albina" și un CRC-16 calculat corect. |
- | You might find this starting script useful: | + | Poate găsiți acest început de script util: |
<code python ex4_draft.py> | <code python ex4_draft.py> | ||
- | from format_funcs import * | + | from utils import * |
def main(): | def main(): | ||
- | |||
# Plaintexts | # Plaintexts | ||
- | s1 = 'floare' | + | s1 = "floare" |
- | s2 = 'albina' | + | s2 = "albina" |
- | G = '' # To find | + | G = "" # To find |
# Obtain crc of s1 | # Obtain crc of s1 | ||
Line 130: | Line 131: | ||
x2 = str_2_hex(s2) | x2 = str_2_hex(s2) | ||
print("x1: " + x1) | print("x1: " + x1) | ||
- | crc1 = '8E31' # CRC-16 of x1 | + | crc1 = "8E31" # CRC-16 of x1 |
# Compute delta (xor) of x1 and x2: | # Compute delta (xor) of x1 and x2: | ||
xd = hexxor(x1, x2) | xd = hexxor(x1, x2) | ||
print("xd: " + xd) | print("xd: " + xd) | ||
+ | |||
+ | # TODO: | ||
Line 142: | Line 145: | ||
<note tip> | <note tip> | ||
- | Use the property for CRC-16 that CRC(m XOR d) = CRC(m) XOR CRC(d). | + | Folosiți proprietatea pentru CRC-16 cum că CRC(m XOR d) = CRC(m) XOR CRC(d). |
- | If d = 'floare' XOR 'albina' and C = [C1 | C2] = [m XOR G1 | CRC(m) XOR G2], then C1' = C1 XOR d. | + | Dacă d = 'floare' XOR 'albina', iar C = [C1 | C2] = [m XOR G1 | CRC(m) XOR G2], atunci C1' = C1 XOR d. |
</note> | </note> | ||
+ | </hidden> |