From 3bdb333dc00738fd3c4f2b4ec441668f4d63376d Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 26 Nov 2023 20:21:15 +0200 Subject: [PATCH] Add the keys module to generate the subkeys. --- cryptography_s_des_exploring/sdes/keys.py | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 cryptography_s_des_exploring/sdes/keys.py diff --git a/cryptography_s_des_exploring/sdes/keys.py b/cryptography_s_des_exploring/sdes/keys.py new file mode 100644 index 0000000..58d4a9a --- /dev/null +++ b/cryptography_s_des_exploring/sdes/keys.py @@ -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 +