10.6. MATLAB Files

10.6.1. RC4 Encryption

 %Initialize the secret key MyKey(1)=164; MyKey(2)=4; MyKey(3)=24; MyKey(4)=107; MyKey(5)=251; MyKey(6)=66; MyKey(7)=186; MyKey(8)=95; %Initialize data data=round(rand(1,300)*256); %Create an array of size 256 filled with numbers from 0 to 255. for i=1:256 S(i)=i-1; end % Create another array of size 256 filled with repetitions of the key. for i=0:255 K(i+1)=MyKey(mod(i,length(MyKey))+1); end % Initialize the order of S according to the secret key. j=0; for i=0:255 j=mod(j+S(i+1)+K(i+1),256); temp=S(i+1); S(i+1)=S(j+1); S(j+1)=temp; end % The encrypted data is generated one byte at a time. i=0; j=0; for k=1: length(data) i=mod(i+1, 256); j=mod(j+S(i+1), 256); temp=S(i+1); S(i+1)=S(j+1); S(j+1)=temp; t=mod(S(i+1)+S(j+1),256); ...

Get Home Network Basis: Transmission Environments and Wired/Wireless Protocols now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.