<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="generator" content="pdf2htmlEX">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css">
<link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css">
<link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/622b8dee3d2fbb0007120748/raw.css">
<script src="https://static.pudn.com/base/js/compatibility.min.js"></script>
<script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script>
<script>
try{
pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({});
}catch(e){}
</script>
<title></title>
</head>
<body>
<div id="sidebar" style="display: none">
<div id="outline">
</div>
</div>
<div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/622b8dee3d2fbb0007120748/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">Des algo in matlab</div><div class="t m0 x1 h4 y3 ff2 fs1 fc1 sc0 ls0 ws0">function [varargout] = DES(input64,mode,key)</div><div class="t m0 x1 h4 y4 ff2 fs1 fc1 sc0 ls0 ws0">%DES: Data Encryption Standard</div><div class="t m0 x1 h4 y5 ff2 fs1 fc1 sc0 ls0 ws0">% Encrypt/Decrypt a 64-bit message using a 64-bit key using the Feistel Network</div><div class="t m0 x1 h4 y6 ff2 fs1 fc1 sc0 ls0 ws0">% -------------------------------------------------------------------------</div><div class="t m0 x1 h4 y7 ff2 fs1 fc1 sc0 ls0 ws0">% Inputs: </div><div class="t m0 x1 h4 y8 ff2 fs1 fc1 sc0 ls0 ws0">% input64 = a 64-bit message </div><div class="t m0 x1 h4 y9 ff2 fs1 fc1 sc0 ls0 ws0">% mode = either 'ENC' encryption or 'DEC' decryption (default 'ENC')</div><div class="t m0 x1 h4 ya ff2 fs1 fc1 sc0 ls0 ws0">% key = a 56/64-bit key (optional under 'ENC', but mandatory under 'DEC')</div><div class="t m0 x1 h4 yb ff2 fs1 fc1 sc0 ls0 ws0">% Outputs:</div><div class="t m0 x1 h4 yc ff2 fs1 fc1 sc0 ls0 ws0">% varargout{1} = output64, a 64-bit message after encryption/decryption</div><div class="t m0 x1 h4 yd ff2 fs1 fc1 sc0 ls0 ws0">% varargout{2} = a 64-bit key, if a 64-bit key is not provided as an input</div><div class="t m0 x1 h4 ye ff2 fs1 fc1 sc0 ls0 ws0">% -------------------------------------------------------------------------</div><div class="t m0 x1 h4 yf ff2 fs1 fc1 sc0 ls0 ws0">% Demos:</div><div class="t m0 x1 h4 y10 ff2 fs1 fc1 sc0 ls0 ws0">% plaintext = round(rand(1,64));</div><div class="t m0 x1 h4 y11 ff2 fs1 fc1 sc0 ls0 ws0">% [ciphertext,key] = DES(plaintext); % Encryption syntex 1</div><div class="t m0 x1 h4 y12 ff2 fs1 fc1 sc0 ls0 ws0">% [ciphertext1,key] = DES(plaintext,'ENC'); % Encryption syntex 2</div><div class="t m0 x1 h4 y13 ff2 fs1 fc1 sc0 ls0 ws0">% deciphertext1 = DES(ciphertext1,'DEC',key);% Decryption syntex</div><div class="t m0 x1 h4 y14 ff2 fs1 fc1 sc0 ls0 ws0">% </div><div class="t m0 x1 h4 y15 ff2 fs1 fc1 sc0 ls0 ws0">% key56 = round(rand(1,56));</div><div class="t m0 x1 h4 y16 ff2 fs1 fc1 sc0 ls0 ws0">% [ciphertext2,key64] = DES(plaintext,'ENC',key56);% Encryption syntex 3 (56-bit key)</div><div class="t m0 x1 h4 y17 ff2 fs1 fc1 sc0 ls0 ws0">% deciphertext2 = DES(ciphertext2,'DEC',key64); % Decryption syntex (64-bit key)</div><div class="t m0 x1 h4 y18 ff2 fs1 fc1 sc0 ls0 ws0">% ciphertext3 = DES(plaintext,'ENC',key64); % Encryption syntex 3 (64-bit key)</div><div class="t m0 x1 h4 y19 ff2 fs1 fc1 sc0 ls0 ws0">% deciphertext3 = DES(ciphertext3,'DEC',key56); % Decryption syntex (56-bit key)</div><div class="t m0 x1 h4 y1a ff2 fs1 fc1 sc0 ls0 ws0">% </div><div class="t m0 x1 h4 y1b ff2 fs1 fc1 sc0 ls0 ws0">% % plot results</div><div class="t m0 x1 h4 y1c ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,1),plot(plaintext),ylim([-.5,1.5]),xlim([1,64]),title('plaintext')</div><div class="t m0 x1 h4 y1d ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,2),plot(ciphertext),ylim([-.5,1.5]),xlim([1,64]),title('ciphertext')</div><div class="t m0 x1 h4 y1e ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,3),plot(deciphertext1),ylim([-.5,1.5]),xlim([1,64]),title('deciphertext1')</div><div class="t m0 x1 h4 y1f ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,4),plot(ciphertext1),ylim([-.5,1.5]),xlim([1,64]),title('ciphertext1')</div><div class="t m0 x1 h4 y20 ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,5),plot(deciphertext2),ylim([-.5,1.5]),xlim([1,64]),title('deciphertext2')</div><div class="t m0 x1 h4 y21 ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,6),plot(ciphertext2),ylim([-.5,1.5]),xlim([1,64]),title('ciphertext2')</div><div class="t m0 x1 h4 y22 ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,7),plot(deciphertext3),ylim([-.5,1.5]),xlim([1,64]),title('deciphertext3')</div><div class="t m0 x1 h4 y23 ff2 fs1 fc1 sc0 ls0 ws0">% subplot(4,2,8),plot(ciphertext3),ylim([-.5,1.5]),xlim([1,64]),title('ciphertext3')</div><div class="t m0 x1 h4 y24 ff2 fs1 fc1 sc0 ls0 ws0">% -------------------------------------------------------------------------</div><div class="t m0 x1 h4 y25 ff2 fs1 fc1 sc0 ls0 ws0">% NOTE: </div><div class="t m0 x1 h4 y26 ff2 fs1 fc1 sc0 ls0 ws0">% 1. If a 64-bit key is provided, then its bit parities will be checked. If</div><div class="t m0 x1 h4 y27 ff2 fs1 fc1 sc0 ls0 ws0">% a 56-bit key is provided, then it is automatically added 8 partity</div><div class="t m0 x1 h4 y28 ff2 fs1 fc1 sc0 ls0 ws0">% checking bits. However, the 8 parity bits are never used in</div><div class="t m0 x1 h4 y29 ff2 fs1 fc1 sc0 ls0 ws0">% DES encryption/decryption process. They are included just for the </div><div class="t m0 x1 h4 y2a ff2 fs1 fc1 sc0 ls0 ws0">% completeness of a DES implementation. </div><div class="t m0 x1 h4 y2b ff2 fs1 fc1 sc0 ls0 ws0">% 2. Cipher modes are not provided in this simple script. If you are </div><div class="t m0 x1 h4 y2c ff2 fs1 fc1 sc0 ls0 ws0">% interested or do not know what does cipher modes mean, please go to page</div><div class="t m0 x1 h4 y2d ff2 fs1 fc1 sc0 ls0 ws0">% http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation</div><div class="t m0 x1 h4 y2e ff2 fs1 fc1 sc0 ls0 ws0">% for details. Please keep in mind that selecting an inappropriate working</div><div class="t m0 x1 h4 y2f ff2 fs1 fc1 sc0 ls0 ws0">% mode may extremely weaken the security of your messages.</div><div class="t m0 x1 h4 y30 ff2 fs1 fc1 sc0 ls0 ws0">% 3. A general description of DES can be found at its wiki page:</div><div class="t m0 x1 h4 y31 ff2 fs1 fc1 sc0 ls0 ws0">% http://en.wikipedia.org/wiki/Data_Encryption_Standard</div><div class="t m0 x1 h4 y32 ff2 fs1 fc1 sc0 ls0 ws0">% The detailed cryptographical primitives can be found under the page:</div><div class="t m0 x1 h4 y33 ff2 fs1 fc1 sc0 ls0 ws0">% http://en.wikipedia.org/wiki/DES_supplementary_material</div><div class="t m0 x1 h4 y34 ff2 fs1 fc1 sc0 ls0 ws0">% If you want to speed-up the DES code here, you can simply store these</div><div class="t m0 x1 h4 y35 ff2 fs1 fc1 sc0 ls0 ws0">% primitives in memory and call them when you need. </div><div class="t m0 x1 h4 y36 ff2 fs1 fc1 sc0 ls0 ws0">% -------------------------------------------------------------------------</div><div class="t m0 x1 h4 y37 ff2 fs1 fc1 sc0 ls0 ws0">% By Yue (Rex) Wu</div><div class="t m0 x1 h4 y38 ff2 fs1 fc1 sc0 ls0 ws0">% ECE Dept @ Tufts Univ.</div></div></div><div class="pi" data-data='{"ctm":[1.568627,0.000000,0.000000,1.568627,0.000000,0.000000]}'></div></div>
</body>
</html>