This shows you the differences between two versions of the page.
|
ic:laboratoare:05 [2020/11/04 09:43] philip.dumitru [Exercise 3 (5p)] |
ic:laboratoare:05 [2020/11/04 14:00] (current) philip.dumitru [Exercise 3 (5p)] |
||
|---|---|---|---|
| Line 58: | Line 58: | ||
| def string_to_bytes(string_data): | def string_to_bytes(string_data): | ||
| return string_data.encode() # default utf-8 | return string_data.encode() # default utf-8 | ||
| + | | ||
| + | # THIS ONE IS NEW | ||
| + | def hex_2_bytes(hex_data): | ||
| + | return bytes.fromhex(hex_data) # default utf-8 | ||
| </file> | </file> | ||
| Line 183: | Line 187: | ||
| The bytestring ciphertext c | The bytestring ciphertext c | ||
| """ | """ | ||
| - | d = DES.new(k) | + | d = DES.new(k, DES.MODE_ECB) |
| c = d.encrypt(m) | c = d.encrypt(m) | ||
| return c | return c | ||
| Line 203: | Line 207: | ||
| The bytestring plaintext m | The bytestring plaintext m | ||
| """ | """ | ||
| - | d = DES.new(k) | + | d = DES.new(k, DES.MODE_ECB) |
| m = d.decrypt(c) | m = d.decrypt(c) | ||
| return m | return m | ||