Add the keys module to generate the subkeys.

This commit is contained in:
2023-11-26 20:21:15 +02:00
parent 0f0be06385
commit 3bdb333dc0
+24
View File
@@ -0,0 +1,24 @@
from cryptography_s_des_exploring.sdes.sdes import apply_table, left_shift, p8_table, p10_table
def generate_subkeys(key: str):
"""
Returns generated two subkeys: K1, K2 - from the 10-bit key
key is a binary which represented with a 10 character string.
"""
temp = apply_table(key, p10_table)
left = temp[:5]
right = temp[5:]
left = left_shift(left)
right = left_shift(right)
key1 = apply_table(left + right, p8_table)
left = left_shift(left)
right = left_shift(right)
left = left_shift(left)
right = left_shift(right)
key2 = apply_table(left + right, p8_table)
return key1, key2