Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ic:laboratoare:02 [2020/10/07 20:13]
acosmin.maria
ic:laboratoare:02 [2020/10/19 14:38] (current)
acosmin.maria
Line 11: Line 11:
   * **ex2.py**: implementation of exercise 2;   * **ex2.py**: implementation of exercise 2;
   * **ex3.py**: implementation of exercise 3.   * **ex3.py**: implementation of exercise 3.
 +
 You need to fill in the TODOs from **ex1.py**, **ex2.py**, and **ex3.py**. You need to fill in the TODOs from **ex1.py**, **ex2.py**, and **ex3.py**.
 +
 ==== Exercise 1 (2p) ==== ==== Exercise 1 (2p) ====
  
 Alice sends Bob the following ciphertexts:​ Alice sends Bob the following ciphertexts:​
- 
 <​code>​ <​code>​
 LDPWKHORUGBRXUJRG LDPWKHORUGBRXUJRG
Line 32: Line 33:
 Charlie manages to capture the ciphertexts and he finds that the cipher used for Charlie manages to capture the ciphertexts and he finds that the cipher used for
 encryption is the shift cipher (each message possibly encrypted with a different encryption is the shift cipher (each message possibly encrypted with a different
-key). Can you decrypt the messages ?+key). Can you decrypt the messages?
  
 Charlie also knows that the plaintext consists only of the English letters A to Charlie also knows that the plaintext consists only of the English letters A to
Line 43: Line 44:
 ==== Exercise 2 (4p) ==== ==== Exercise 2 (4p) ====
  
-Alice sends Bob another ciphertext, but much longer this time:+Alice sends Bob another ciphertext, but much longer this time...
  
-{{:sasc:laboratoare:sasc_msg_lab1.txt|Download message file}}+{{:ic:res:msg_ex2.txt|Download message file}}
  
 Charlie needs to decrypt this as well. Some colleagues tell him this is encrypted Charlie needs to decrypt this as well. Some colleagues tell him this is encrypted
 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. 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: 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):+**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**
  
Line 58: Line 59:
 ==== Exercise 3 (4p) ==== ==== Exercise 3 (4p) ====
  
-Charlie manages to capture {{:sasc:laboratoare:sasc_msg_lab2.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 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.
  
 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]]. 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]].
Line 95: Line 96:
 ==== Bonus: Exercise 4 (2p) ==== ==== Bonus: Exercise 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.+In classwe 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.
  
 You are given the following ciphertext in hexadecimal:​ You are given the following ciphertext in hexadecimal:​
Line 111: Line 112:
 You might find this starting script useful: You might find this starting script useful:
 <code python ex4_draft.py>​ <code python ex4_draft.py>​
-import ​sys +from format_funcs ​import ​*
-import random +
-import string +
-import operator +
- +
-def strxor(a, b): # xor two strings (trims the longer input) +
-  return ""​.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])+
  
-def hexxor(a, b): # xor two hex strings (trims the longer input) 
-  ha = a.decode('​hex'​) 
-  hb = b.decode('​hex'​) 
-  return ""​.join([chr(ord(x) ^ ord(y)).encode('​hex'​) for (x, y) in zip(ha, hb)]) 
  
 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 
-  #See this site: +    # See this site: 
-  #​http://​www.lammertbies.nl/​comm/​info/​crc-calculation.html +    # http://​www.lammertbies.nl/​comm/​info/​crc-calculation.html 
-  x1 = s1.encode('​hex'​+    x1 = str_2_hex(s1) 
-  x2 = s2.encode('​hex'​+    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)
  
  
 if __name__ == "​__main__":​ if __name__ == "​__main__":​
-  ​main()+    ​main()
 </​code>​ </​code>​
  
ic/laboratoare/02.1602090824.txt.gz · Last modified: 2020/10/07 20:13 by acosmin.maria
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0