-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOFB_mode.py
More file actions
71 lines (56 loc) · 1.97 KB
/
Copy pathOFB_mode.py
File metadata and controls
71 lines (56 loc) · 1.97 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
Created on Mar 20, 2017
This is a module for the OFB mode of encryption where the IV is first fed into the encryption algorithm and the output is then XOR'd with the Plain-text to produce the
Cipher-text and the output from the algorithm is used as an IV for the next round/block.
@author: SaathvikPrasad
'''
import SdesEncrypt
Enc_Message_ofb = []
Dec_Message_ofb = []
'''function for encryption using OFB mode of operation'''
def ofb_enc(msg,para_key,IV):
ctr = 1
i = 0
ET,CT = [],[]
while(i<len(msg)):
P = msg[i:i+12]
if ctr==1:
ek,Pdt = SdesEncrypt.desenc(para_key, IV)
ET = ''.join(Pdt)
CT = SdesEncrypt.exorbits(ET, P)
i = i+12
ctr = ctr + 1
Enc_Message_ofb.append(''.join(map(str,CT)))
else:
ek,Pdt = SdesEncrypt.desenc(para_key, ET)
ET = ''.join(Pdt)
CT = SdesEncrypt.exorbits(ET, P)
Enc_Message_ofb.append(''.join(map(str,CT)))
i = i + 12
ctr = ctr + 1
emofb = ''.join(map(str,Enc_Message_ofb))
return ek,emofb
'''function for decryption using OFB mode of operation'''
def ofb_dec(msg,para_key,IV):
Msg = list(msg)
PT, ET = [],[]
ctr = 1
i = 0
while(i<len(Msg)):
C = Msg[i:i+12]
if ctr == 1:
ek,Pdt = SdesEncrypt.desenc(para_key, IV)
ET = ''.join(Pdt)
PT = SdesEncrypt.exorbits(ET,C)
Dec_Message_ofb.append(''.join(map(str,PT)))
i = i + 12
ctr = ctr + 1
else:
ek,Pdt = SdesEncrypt.desenc(para_key, ET)
ET = ''.join(Pdt)
PT = SdesEncrypt.exorbits(ET,C)
Dec_Message_ofb.append(''.join(map(str,PT)))
i = i + 12
ctr = ctr + 1
dmofb = ''.join(map(str,Dec_Message_ofb))
return dmofb