-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRound.py
More file actions
25 lines (19 loc) · 667 Bytes
/
Round.py
File metadata and controls
25 lines (19 loc) · 667 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
from des import NoneSwapper, Swapper, Mixer
class Round:
def __init__(self, mixer):
self.mixer = mixer
self.swapper = NoneSwapper()
@staticmethod
def with_swapper(mixer: Mixer):
temp = Round(mixer)
temp.swapper = Swapper(block_size=mixer.block_size)
return temp
@staticmethod
def without_swapper(mixer: Mixer):
return Round(mixer)
def encrypt(self, binary: str) -> str:
binary = self.mixer.encrypt(binary)
return self.swapper.encrypt(binary)
def decrypt(self, binary: str) -> str:
binary = self.swapper.decrypt(binary)
return self.mixer.decrypt(binary)