Differences

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

Link to this comparison view

ic:labs:04 [2023/10/01 23:23]
razvan.smadu [Laboratorul 04 - PRFs, PRPs, SPNs]
ic:labs:04 [2023/10/09 23:21] (current)
razvan.smadu
Line 3: Line 3:
 Prezentarea PowerPoint pentru acest laborator poate fi găsită [[https://​drive.google.com/​file/​d/​1mjbkxFqYNB-lRRXGAhsdh1vK9nwbnDuS/​view?​usp=sharing|aici]]. Prezentarea PowerPoint pentru acest laborator poate fi găsită [[https://​drive.google.com/​file/​d/​1mjbkxFqYNB-lRRXGAhsdh1vK9nwbnDuS/​view?​usp=sharing|aici]].
  
-Puteți lucra acest laborator folosind ​și platforma Google Colab, accesând [[https://​colab.research.google.com/​drive/1rxZ9eyzMXqq3NDia22suPO_1QPAb5o0C?​usp=sharing+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/​lab04/​lab4.ipynb
 |acest]] link. |acest]] link.
  
 +<​hidden>​
 <spoiler Click pentru a vedea utils.py>​ <spoiler Click pentru a vedea utils.py>​
 <file python utils.py>​ <file python utils.py>​
Line 433: Line 434:
  
  
-def permute4_32(s:​ str) -> str: 
-    """​Perform a permutatation by shifting all bits 4 positions right. 
- 
-    Args: 
-        s (str): The input is assumed to be a 32-bit bitstring. 
- 
-    Raises: 
-        TypeError: Expected input to be a string. 
-        ValueError: Expected input to have length 32. 
- 
-    Returns: 
-        str: The permuted string by shifting all bits 4 positions right. 
-    """​ 
-    if not isinstance(s,​ str): 
-        raise TypeError( 
-            f"​Invalid type for the input. Expected `str`, but got `{type(s)}`."​ 
-        ) 
-    if len(s) != 32: 
-        raise ValueError( 
-            f"​Invalit input length. Expected to be 32, but got {len(s)}."​ 
-        ) 
-    return s[28:32] + s[0:28] 
- 
- 
-def permute_inv4_32(s:​ str) -> str: 
-    """​Perform the inverse of permute4_32. 
- 
-    Args: 
-        s (str): The input is assumed to be a 32-bit bitstring. 
- 
-    Raises: 
-        TypeError: Expected input to be a string. 
-        ValueError: Expected input to have length 32. 
- 
-    Returns: 
-        str: The permuted string by shifting all bits 4 positions left. 
-    """​ 
-    if not isinstance(s,​ str): 
-        raise TypeError( 
-            f"​Invalid type for the input. Expected `str`, but got `{type(s)}`."​ 
-        ) 
-    if len(s) != 32: 
-        raise ValueError( 
-            f"​Invalit input length. Expected to be 32, but got {len(s)}."​ 
-        ) 
-    return s[4:32] + s[0:4] 
  
  
Line 597: Line 552:
  
     return y1 + y2     return y1 + y2
 +
 +
  
  
Line 603: Line 560:
     msg = "​Hi"​     msg = "​Hi"​
     key = "??" ​ # Find the key that should replace ??     key = "??" ​ # Find the key that should replace ??
 +    ks = str_2_bin(key)
 +
 +    # TODO 1: Find the key in the reduced 2-byte SPN
 +
  
     xs = str_2_bin(msg)     xs = str_2_bin(msg)
-    ks = str_2_bin(key) 
     ys = spn_1r_reduced_2s(ks,​ xs)     ys = spn_1r_reduced_2s(ks,​ xs)
     print(     print(
-        ​f"Two y halves of reduced SPN:"+        "Two y halves of reduced SPN:"
         f" {ys[0:8]} (hex: {bin_2_hex(ys[0:​8])}),"​         f" {ys[0:8]} (hex: {bin_2_hex(ys[0:​8])}),"​
         f" {ys[8:16]} (hex: {bin_2_hex(ys[8:​16])})"​         f" {ys[8:16]} (hex: {bin_2_hex(ys[8:​16])})"​
Line 616: Line 576:
     msg = "​Om"​     msg = "​Om"​
     key = "????" ​ # Find the key that should replace ????     key = "????" ​ # Find the key that should replace ????
-    xs = str_2_bin(msg) 
     ks = str_2_bin(key)     ks = str_2_bin(key)
 +
 +    # TODO 2: Find the key in the full 2-byte SPN
 +
 +    xs = str_2_bin(msg)
     ys = spn_1r_full_2s(ks,​ xs)     ys = spn_1r_full_2s(ks,​ xs)
     print(     print(
-        ​f"Two y halves of full SPN (2 bytes):"​+        "Two y halves of full SPN (2 bytes):"​
         f" {ys[0:8]} (hex: {bin_2_hex(ys[0:​8])}),"​         f" {ys[0:8]} (hex: {bin_2_hex(ys[0:​8])}),"​
         f" {ys[8:16]} (hex: {bin_2_hex(ys[8:​16])})"​         f" {ys[8:16]} (hex: {bin_2_hex(ys[8:​16])})"​
     )     )
 +
  
  
 if __name__ == "​__main__":​ if __name__ == "​__main__":​
-    main() ​+    main()
 </​code>​ </​code>​
 </​spoiler>​ </​spoiler>​
Line 655: Line 619:
 De data aceasta nu se poate executa o cautare brute-force pe toți octeții de XOR. Încercați să atacați câte un S-box pe rând. Gandiți-vă ce biți sunt afectați de fiecare S-box pentru a construi un atac eficient. Ce se întâmplă dacă faceți brute force pe k5 și k6? Puteți să aflați k1? De data aceasta nu se poate executa o cautare brute-force pe toți octeții de XOR. Încercați să atacați câte un S-box pe rând. Gandiți-vă ce biți sunt afectați de fiecare S-box pentru a construi un atac eficient. Ce se întâmplă dacă faceți brute force pe k5 și k6? Puteți să aflați k1?
 </​note>​ </​note>​
 +</​hidden>​
ic/labs/04.1696191795.txt.gz · Last modified: 2023/10/01 23:23 by razvan.smadu
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