-
Notifications
You must be signed in to change notification settings - Fork 0
/
decryption.py
38 lines (28 loc) · 994 Bytes
/
decryption.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import s_des as moduless
import key_generation as keyer
s1 = keyer.Keyer()
s3 = moduless.SDES()
class Dec:
def decrypt(self, ciphertext : str, key : str) -> str :
# intial permutation
ciphertext = s3.perFirst(ciphertext)
r1, r2 = s1.generateRoundKey(key)
# round function
right1 = ciphertext[4:]
round_right1 = s3.roundFunction(right1, r2)
left1 = ciphertext[:4]
# XORing
newLeft1 = ""
for i in range(len(left1)):
newLeft1 += str(int(left1[i]) ^ int(round_right1[i]))
# swapper
right2 = newLeft1
round_right2 = s3.roundFunction(right2, r1)
left2 = right1
# XORing
newLeft2 = ""
for i in range(len(left2)):
newLeft2 += str(int(left2[i]) ^ int(round_right2[i]))
final = newLeft2 + right2
plaintext = s3.perLast(final)
return plaintext