Date post: | 07-Apr-2018 |
Category: |
Documents |
Upload: | khurram-hashmi |
View: | 215 times |
Download: | 0 times |
of 26
8/3/2019 DES (code)
1/26
DATA ENCRYPTION
STANDARD(DES)
by Engr. Khurram Hashmi
8/3/2019 DES (code)
2/26
Cryptography
8/3/2019 DES (code)
3/26
Block Ciphers
Block ofplain Text
Size: (M)
CipherEncryption
Algorithm
Block ofcipher Text
Size : (M)
Secret key
8/3/2019 DES (code)
4/26
Background
The Data Encryption Standard (DES) is a blockcipher that uses shared secret encryption.
It was selected by the National Bureau of Standards asan official Federal Information Processing
Standard (FIPS) for the United States in 1976 Has subsequently enjoyed widespread use
internationally.
The algorithm was initially controversial because
of classified design elements DES consequently came under intense academic
analysis which motivated the modern understandingof block ciphers and their cryptanalysis.
8/3/2019 DES (code)
5/26
Shortfalls
DES is now considered to be insecure for many applications.Chiefly due to the 56-bit key size being too small.
The basic method of attack is brute force trying everypossible key in turn.
The length of the key determines the number of possiblekeys.
DES has a small key size 56-bits and this approach isfeasible for breaking it
Questions were raised about the adequacy of DES key sizeeven before it was adopted as a standard, and it was thesmall key size, rather than theoretical cryptanalysis, whichdictated a need for a replacement algorithm
8/3/2019 DES (code)
6/26
Data Encryption Standard
It is a block Cipher
Data is encrypted block by block i.e. 64 bits each
time
plain Text64 bit blocks
CipherEncryptionAlgorithm
16 cycles
Cipher Text64 bit blocks
Secret key64 bits
N Blocks N Blocks
56 bits used
8/3/2019 DES (code)
7/26
Encryption Algorithm
Data is processed as 32 bithalf-blocks
Takes 16 rounds to complete
In each round, a new sub-key from the key schedulerisutilized
Data is swapped after each
round except the last Initial and final permutations
are Inverses of each other
48 bitSub-key
48 bitSub-key
32bit32bit
XOR
8/3/2019 DES (code)
8/26
8/3/2019 DES (code)
9/26
Structure
BinaryInput
One Dimensional arrays.
For loops
While loops
Function calling
Sub function calling
1 2 3 4 5 6 ... ... ... N
8/3/2019 DES (code)
10/26
Main
A=round(rand(1,64))
B=P1(A);
[l,r]=LR(B);
[l,r]= mnalgo(l,r);
C=LRbk(l,r);
D=P2(C)
64 elements (random)
32 elements 32 elements
64 elements (permuted)
Expansionkey XOR
Compression (S-Box)
P-Box
64 element final permt
L
Script file
64 element (cipher text)
R
16 cycles
8/3/2019 DES (code)
11/26
Initial Permutation: P1( )
function [b]= P1(a)
Shif=[58 50 42 34 26 18 10 2;
60 52 44 36 28 20 12 4;
62 54 46 38 30 22 14 6;
64 56 48 40 32 24 16 8;
57 49 41 33 25 17 9 1;
59 51 43 35 27 19 11 3;
61 53 45 37 29 21 13 5;
63 55 47 39 31 23 15 7;];
l=1; % extra counter
for i= 1:8, %rows
for j= 1:8, %columns
b(1,l)=a(1,Shif(i,j)); %the actual guided shifting
l=l+1; % extra counter increment
end
end
1 2 3 4 5 . . 58 . 64
58 50 42 34 26 . . . . 7
58
a original array
b shifting / swapping
b shifted / swapped array
8/3/2019 DES (code)
12/26
16 cycles: Main algorithm ( )
function[l,r]= mnalgo(l,r)
cnt=0; %counter intialization
while cnt
8/3/2019 DES (code)
13/26
Left Right Breaking: LR( )
function[l,r]=LR(c)
l(1,1:32)=c(1,1:32); %the first 32 of the input elements
r(1,1:32)=c(1,33:64); %the next 32 of the input elements
1.32 33..64
1.64
left right
8/3/2019 DES (code)
14/26
8/3/2019 DES (code)
15/26
Expansion and key XOR ( )
function [b]= E(a)
Ex=[32 1 2 3 4 5;
4 5 6 7 8 9;
8 9 10 11 12 13;
12 13 14 15 16 17;
16 17 18 19 20 21;
20 21 22 23 24 25;
24 25 26 27 28 29;
26 29 30 31 32 1;];
l=1; %extra variable
for i= 1:8, %rows
for j= 1:6, %columns
b(1,l)=a(1,Ex(i,j)); %the actual guided shifting
l=l+1; %extra increment
end
end
Duplication of two columns
Expansion Table
32 1
1 2 .. . .. 32
32 1 2 3 4 5 4 5 6
8/3/2019 DES (code)
16/26
Expansion and key XOR (b)
key=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0]; %48 bitkey
b= xor (b,key);1 2 3 48
1 1 1 0 1
XOR
1 2 3 48
keyExpanded array
8/3/2019 DES (code)
17/26
S-Box Compression
function [b]= S(a)
% where a is a 48 element binary array
t=[14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7;
0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8;
4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0;
15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 14]; %S-box Table
8/3/2019 DES (code)
18/26
S-Box Compression
6bit 6bit 6bit 6bit
011011
01
1101
1
13
rows
columns
temp
cnv( )
cnv4( ) S-Box Tableref
Binary to decimal
91001Decimal to Binary
4bit
32 bit
4 bit
Replacement element
48 bit
+1
8/3/2019 DES (code)
19/26
S-Box Look up table
S5Middle 4 bits of input
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Outer
bits
00 0010 1100 0100 0001 0111 1010 1011 0110 1000 0101 0011 1111 1101 0000 1110 100101 1110 1011 0010 1100 0100 0111 1101 0001 0101 0000 1111 1010 0011 1001 1000 0110
10 0100 0010 0001 1011 1010 1101 0111 1000 1111 1001 1100 0101 0110 0011 0000 111011 1011 1000 1100 0111 0001 1110 0010 1101 0110 1111 0000 1001 1010 0100 0101 0011
Input: 011011 Output: 1001
Non Linear Transformation
8/3/2019 DES (code)
20/26
4bit
S-Box: While loop
i=1; j=1; l=1; cn=1; %initializing counterswhile i
8/3/2019 DES (code)
21/26
P-Box permutation
%P-Box permutation
P=[16 7 20 21 29 12 28 17 1 15 23 26 5 18 31 10;
2 8 24 14 32 27 3 9 19 13 30 6 22 11 4 25]; % P-box table
l=1; % extra counter
for i= 1:2, %rows
for j= 1:16, %columns
b(1,l)=c(1,P(i,j)); %the actual guided shifting
l=l+1; % extra counter increment
end
end
32 bit Array
P-Box permuted array
8/3/2019 DES (code)
22/26
Final Permutation: P2( )
function [b]= P2(a)
ip= [58 50 42 34 26 18 10 2;
60 52 44 36 28 20 12 4;
62 54 46 38 30 22 14 6;
64 56 48 40 32 24 16 8;
57 49 41 33 25 17 9 1;
59 51 43 35 27 19 11 3;
61 53 45 37 29 21 13 5;
63 55 47 39 31 23 15 7;];
The initial permutation table
Generating a reverse permutation array that reverses the initial permutation
58 50 42 34 26 18 10 2
8/3/2019 DES (code)
23/26
Final Permutation: P2( )c=1;
for x= 1:64
l=1;
for i= 1:8,
for j= 1:8,
ifip(i,j) = = x;
iprev(1,c) =l;
c=c+1;
else
;
end
l=l+1;
end
end
end
%iprev
for j= 1:64, %coloumns
b(1,j)=a(1,iprev(1,j)); %the actual guided shifting
%l=l+1; % extra counter incrementend
58 50 y
7
Reverse Reference index iprev
Reverse permuted array
Initialpermutationtable
8/3/2019 DES (code)
24/26
Binary to Decimal conversion
function[b]=cnv(a)
%where a is a 2 bit array
c=0000;
c=(a(1,1)*10)+c;
c= a(1,2)+c;
b=int2str(c);
b=bin2dec(b);
1 1
c=0000
0010
0011
3
0011
int2str( )
bin2dec ( )
10
8/3/2019 DES (code)
25/26
Encryption
plain Text64 bit blocks
CipherEncryptionAlgorithm
16 cycles
Cipher Text64 bit blocks
Secret key64 bits
N Blocks N Blocks
56 bits used
8/3/2019 DES (code)
26/26
Questions are Welcome
Thank You