-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeistel_structure.py
More file actions
25 lines (20 loc) · 830 Bytes
/
Copy pathfeistel_structure.py
File metadata and controls
25 lines (20 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import copy
from round_functions import round_function
def feistel(input, round_keys, round_function, xor_function, mode):
keys = copy.deepcopy(round_keys)
if mode=='decryption':
keys.reverse()
input = input.upper()
# Perform Feistel rounds
for round_key in keys:
left_half = input[:int(len(input)/2)]
right_half = input[int(len(input)/2):]
new_left_half = right_half[:] #right half becomes new left half
# right half -> round func + XOR
new_right_half = round_function(right_half, round_key)
new_right_half = xor_function(left_half, new_right_half)
input = new_left_half + new_right_half
output = input[int(len(input)/2):] + input[:int(len(input)/2)]
if mode=='decryption':
output = output.upper()
return output