-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.m
94 lines (87 loc) · 2.75 KB
/
decrypt.m
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [plain_text]=decrypt(binary_cipher,K1,K2,K3,K4)
%Decryption
dec=cell(8,4);
% Arranging 64 bit into 16 bit block
dec{1,1}=binary_cipher(1:16);
dec{1,2}=binary_cipher(17:32);
dec{1,3}=binary_cipher(33:48);
dec{1,4}=binary_cipher(49:64);
% for first round
%performing Xnor operation with K4
dec{2,1}=not(xor(K4,dec{1,1}));
%Using f f_function and Xor operation obtain second 16 bit block
dec{2,3}=xor(fun(dec{1,1}),dec{1,2});
%Performing xnor operation on last 16 bit
dec{2,4}=not(xor(K4,dec{1,4}));
%Using f f_function and Xor operation obtain third 16 bit block
dec{2,2}=xor(fun(dec{1,4}),dec{1,3});
%bin_msg=[dec{2,1},dec{2,2},dec{2,3},dec{2,4}];
%step2 swapping blocks
dec{3,1}=dec{2,2};
dec{3,2}=dec{2,1};
dec{3,3}=dec{2,4};
dec{3,4}=dec{2,3};
% for Second Round
%performing Xnor operation with K3
dec{4,1}=not(xor(K3,dec{3,1}));
%Using f f_function and Xor operation obtain second 16 bit block
dec{4,3}=xor(fun(dec{3,1}),dec{3,2});
%Performing xnor operation on last 16 bit
dec{4,4}=not(xor(K3,dec{3,4}));
%Using f f_function and Xor operation obtain third 16 bit block
dec{4,2}=xor(fun(dec{3,4}),dec{3,3});
%step2 swapping blocks
dec{5,1}=dec{4,2};
dec{5,2}=dec{4,1};
dec{5,3}=dec{4,4};
dec{5,4}=dec{4,3};
% for Third Round
%Step no 01
%Step no 02
%performing xnor operation in first 16 bits with K2
dec{6,1}=not(xor(K2,dec{5,1}));
% Using f f_function and swaping tecniques on 16 bit
dec{6,3}=xor(fun(dec{5,1}),dec{5,2});
%performing xnor operation in last 16 bits with K1
dec{6,4}=not(xor(K2,dec{5,4}));
% Usin f f_function and swaping tecniques on 16 bit
dec{6,2}=xor(fun(dec{5,4}),dec{5,3});
%night e kaj korbo
%step2 swapping blocks
dec{7,1}=dec{6,2};
dec{7,2}=dec{6,1};
dec{7,3}=dec{6,4};
dec{7,4}=dec{6,3};
% for fourth Round
%performing Xnor operation with K1
dec{8,1}=not(xor(K1,dec{7,1}));
%Using f f_function and Xor operation obtain second 16 bit block
dec{8,3}=xor(fun(dec{7,1}),dec{7,2});
%Performing xnor operation on last 16 bit
dec{8,4}=not(xor(K1,dec{7,4}));
%Using f f_function and Xor operation obtain third 16 bit block
dec{8,2}=xor(fun(dec{7,4}),dec{7,3});
% for fifth Round
%Step no 01
%Swaping Blocks
%dec{7,1}=dec{6,2};
%dec{7,2}=dec{6,1};
%dec{7,3}=dec{6,4};
%dec{7,4}=dec{6,3};
%Step no 02
%performing xnor operation in first 16 bits with K1
%dec{8,1}=not(xor(K1,dec{7,1}));
% Using f f_function and swaping tecniques on 16 bit
%dec{8,3}=xor(f_fun(dec{7,1}),dec{7,2});
%performing xnor operation in last 16 bits with K1
%dec{8,4}=not(xor(K1,dec{7,4}));
% Using f f_function and swaping tecniques on 16 bit
%dec{8,2}=xor(f_fun(dec{7,4}),dec{7,3});
% %% Modification
% dec{8,1}=dec{3,1};
% dec{8,2}=dec{3,2};
% dec{8,3}=dec{3,3};
% dec{8,4}=dec{3,4};
%plain_text=[dec{2,1},dec{2,2},dec{2,3},dec{2,4}];
plain_text=[dec{8,1},dec{8,2},dec{8,3},dec{8,4}];
end