sdes_enc.m

来自「SDES encryption algorithm」· M 代码 · 共 34 行

M
34
字号
%start of encryption data
k = input('Enter key(1 -> 1023) :\n >');
key = de2bi(k,10);
f=fopen('plain text.txt');
[plaintext,Counter]=fread(f);
fclose(f);
f=fopen('plain text.txt');
bin=[];
data=[];
ciphertext=[];
%genrate key1 & key2
[K1,K2]=getkey(key);
for n=1:1:Counter
byte=fread(f,1);
A=de2bi(byte,8);
bin=[bin A];
%permutation 
IP=intrlv(A,[2 6 3 1 4 8 5 7]);
%call fk function with k1
out1=Fk(IP,K1);
SW=[out1(5:8) out1(1:4)];
%call fk function with k2
out2=Fk(SW,K2);
%inverse permutation
negIP=deintrlv(out2,[2 6 3 1 4 8 5 7]);
data=[data negIP];
decdata=bi2de(negIP);
ciphertext=[ciphertext decdata];
end
fclose(f);
f=fopen('cipher text.txt','w');
count=fwrite(f,ciphertext);
fclose(f);
% end of encryption data

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?