Professional Documents
Culture Documents
ACC Project 4 Implementation SDES Ghosia Razaq
ACC Project 4 Implementation SDES Ghosia Razaq
Registration #: MCY231003
def apply_swapper(xor_left_f):
new_left, right = xor_left_f[:len(xor_left_f)//2], xor_left_f[len(xor_left_f)//2:]
return right + new_left
permuted_text = feistel_permutation(permuted_text[len(permuted_text)//2:],
expansion_table)
# first round
permuted_text = feistel(permuted_text, round_keys[0], expansion_table, s_box1, s_box2,
p_box)
#swapper
permuted_text = apply_swapper(permuted_text)
#second round
permuted_text = feistel(permuted_text, round_keys[1], expansion_table, s_box1, s_box2,
p_box)
#final permtation
ciphertext = final_permutation(permuted_text, final_permutation_table)
return ciphertext
#print(ciphertext)
# Define permutation tables
initial_permutation_table = [2, 6, 3, 1, 4, 8, 5, 7]
final_permutation_table = [4, 1, 3, 5, 7, 2, 8, 6]
expansion_table = [4, 1, 2, 3, 2, 3, 4, 1]
# S-box tables
s_box1 = [
[1, 0, 3, 2],
[3, 2, 1, 0],
[0, 2, 1, 3],
[3, 1, 3, 2]
]
s_box2 = [
[0, 1, 2, 3],
[2, 0, 1, 3],
[3, 0, 1, 0],
[2, 1, 0, 3]
]
# P-Box
p_box = [2, 4, 3, 1]
# Example usage:
plaintext = input("Enter plaintext in binary: ")
round_key1 = input("Enter Round Key 1 in binary: ")
round_key2 = input("Enter Round Key 2 in binary: ")
print("Ciphertext:", ciphertext)
**************************************************************************
2. KeyGenerator: inputs Cipherkey (K) from user and generates & returns roundkeys
(K1, K2).
Encryption:
Code:
# P10 permutation table for key generation
P8 = [6, 3, 7, 4, 8, 5, 10, 9]
# Function to generate round keys K1 and K2 from the original 10-bit key
def generate_round_keys(cipher_key):
left_half = key_p10[:5]
right_half = key_p10[5:]
left_half_shifted = left_shift(left_half, 1)
right_half_shifted = left_shift(right_half, 1)
# Permutation P8 to obtain K1
left_half_shifted = left_shift(left_half_shifted, 2)
right_half_shifted = left_shift(right_half_shifted, 2)
********************************************************************************