You are on page 1of 2

function[Left,Right]=IP(A) %A=[0 1 0 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 1 1 0]; IPT=[58:-8:2 60:-8:4 62:-8:6 64:-8:8 57:-8:1 59:-8:3 61:-8:5 63:-8:7]; E(1:64)=A(IPT(1:64)); Left=E(1:32); Right=E(33:64); -----------------------------function[G]=Expen(Right)

%Right=[1 0 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0]; F=[Right(32) Right(1:5) Right(4:9) Right(8:13) Right(12:17) Right(16:21) Right(2 0:25) Right(24:29) Right(28:32) Right(1)]; key(1:24)=1; key(25:48)=[0 1 1 0 1 0 0 0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1 ]; G=xor(key,F); ------------------------------function[J]=SBOX(G) %G=[1 0 1 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 0 1 0 1 1 0 0 1 0]; 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]; R1=[G(1),G(6)]; C1=[G(2:5)]; R1=1+bi2de(fliplr(R1)); C1=1+bi2de(fliplr(C1)); R2=[G(7),G(12)]; C2=[G(8:11)]; R2=1+bi2de(fliplr(R2)); C2=1+bi2de(fliplr(C2)); R3=[G(13),G(18)]; C3=[G(14:17)]; R3=1+bi2de(fliplr(R3)); C3=1+bi2de(fliplr(C3)); R4=[G(19),G(24)]; C4=[G(20:23)]; R4=1+bi2de(fliplr(R4)); C4=1+bi2de(fliplr(C4)); R5=[G(25),G(30)]; C5=[G(26:29)]; R5=1+bi2de(fliplr(R5)); C5=1+bi2de(fliplr(C5)); R6=[G(31),G(36)]; C6=[G(32:35)];

R6=1+bi2de(fliplr(R6)); C6=1+bi2de(fliplr(C6)); R7=[G(37),G(42)]; C7=[G(38:41)]; R7=1+bi2de(fliplr(R7)); C7=1+bi2de(fliplr(C7)); R8=[G(43),G(48)]; C8=[G(44:47)]; R8=1+bi2de(fliplr(R8)); C8=1+bi2de(fliplr(C8)); J1=T(R1,C1); J1=fliplr(de2bi(J1,4)); J2=T(R2,C2); J2=fliplr(de2bi(J2,4)); J3=T(R3,C3); J3=fliplr(de2bi(J3,4)); J4=T(R4,C4); J4=fliplr(de2bi(J4,4)); J5=T(R5,C5); J5=fliplr(de2bi(J5,4)); J6=T(R6,C6); J6=fliplr(de2bi(J6,4)); J7=T(R7,C7); J7=fliplr(de2bi(J7,4)); J8=T(R8,C8); J8=fliplr(de2bi(J8,4)); J=[J1 J2 J3 J4 J5 J6 J7 J8]; ------------------------------------Main ---A=[0 1 0 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0 1 1 0]; [Left,Right]=IP(A) G=Expen(Right) [J]=SBOX(G)

You might also like