]> AND Private Git Repository - Cipher_code.git/blob - Chaotic_code/Dynamickeygenerationnew.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[Cipher_code.git] / Chaotic_code / Dynamickeygenerationnew.m
1 function [RK,Sbox,Pbox]=Dynamickeygenerationnew(Secretkey,counter,strh,h)\r
2 x=java.security.MessageDigest.getInstance(strh);\r
3 x.update(bitxor(Secretkey,counter));\r
4 DK=double(typecast(x.digest,'uint8'));\r
5 M=sqrt(h*8);\r
6 %%%%%%%%%%%% Creation of P-box (blocks permutation)%%%%%%%%%%%%%%%%%%%%%%%%\r
7 % construction of P-box\r
8 \r
9 %Pbox=PermutationCat(Keyp,M);\r
10 \r
11 Qp=8*h;\r
12 Ap=1:Qp;\r
13 Keyp=reshape((DK(1:1:16)),1,[]);\r
14 Keyp=mod(Keyp,Qp)+1;\r
15 \r
16 Pbox=supboxvector2(Ap,Qp,Keyp)\r
17 \r
18 \r
19 \r
20 % construction of S-box\r
21 Q=2^8;\r
22 A=1:Q;\r
23 KS=reshape(DK(17:32),1,[]);\r
24 Sbox=supboxvector2(A,Q,KS)-1;\r
25 \r
26 %%%%%%%%%%%%%%%% Construction of round keys%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \r
27 r=4;\r
28 X=reshape(DK(33:48),1,[]);\r
29 X=double(typecast(uint8(X),'uint32'))\r
30 P=reshape(DK(49:end),1,[]);\r
31 P=double(typecast(uint8(P),'uint32'))\r
32 N=2^32;\r
33 m=ceil(h/4)\r
34 RK= roundKeyiterations(X,P,N,r,Sbox,m);\r
35 \r
36 \r
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
38 % %%%%%%%%%%%%% creation of IV (block of h bits) can be employ for CBC, CFB, OFB, CTR mode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  \r
39 % s_rk=rc4key(DK(17:1:32));\r
40 % IV=reshape(prga( s_rk,h^2),h,h);\r
41 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
42 % %%%%%%%%%%%%%%%%%%%%creation of the diffusion matrix%%%%%%%%%%%%%%%%%%%%%%%\r
43 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
44 % sc2=rc4key(DK(end-16:end));\r
45 % outd=prga( sc2,(h^2)/4);\r
46 % A=reshape(outd,h/2,h/2);\r
47 % In=eye(h/2,h/2);\r
48 % if (kindd==0)\r
49 % G=[A A+In; A-In A ];\r
50 % else\r
51 %  A=mod(A,2);\r
52 %  G=[A        bitxor(A,In) ; bitxor(A,In) A];      \r
53 % end