No BSD License  

Highlights from
Home Networking Basis

Home Networking Basis

by

 

11 Aug 2003 (Updated )

M-files for chapters 2-10 and Simulink models for Ethernet and Wireless Ethernet.

arc4.m
%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);
%Creat an array of size 256 filled with numbers from 0 to 255.
for i=1:256
     S(i)=i-1;
end
% Creat another array of size 256 filled with repetions of the key. 
for i=0:255
     K(i+1)=MyKey(mod(i,length(MyKey))+1);
end
% Initialize the order of S accoding 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);
     PS=S(t+1);
     edata(k)=bitxor(data(k),PS);
end

Contact us