function [RK,Sbox,Pbox]=Dynamickeygenerationnew(Secretkey,counter,strh,h)
x=java.security.MessageDigest.getInstance(strh);
x.update(bitxor(Secretkey,counter));
DK=double(typecast(x.digest,'uint8'));
M=sqrt(h*8);
%%%%%%%%%%%% Creation of P-box (blocks permutation)%%%%%%%%%%%%%%%%%%%%%%%%
% construction of P-box

%Pbox=PermutationCat(Keyp,M);

Qp=8*h;
Ap=1:Qp;
Keyp=reshape((DK(1:1:16)),1,[]);
Keyp=mod(Keyp,Qp)+1;

Pbox=supboxvector2(Ap,Qp,Keyp)



% construction of S-box
Q=2^8;
A=1:Q;
KS=reshape(DK(17:32),1,[]);
Sbox=supboxvector2(A,Q,KS)-1;

%%%%%%%%%%%%%%%% Construction of round keys%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
r=4;
X=reshape(DK(33:48),1,[]);
X=double(typecast(uint8(X),'uint32'))
P=reshape(DK(49:end),1,[]);
P=double(typecast(uint8(P),'uint32'))
N=2^32;
m=ceil(h/4)
RK= roundKeyiterations(X,P,N,r,Sbox,m);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%% creation of IV (block of h bits) can be employ for CBC, CFB, OFB, CTR mode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
% s_rk=rc4key(DK(17:1:32));
% IV=reshape(prga( s_rk,h^2),h,h);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%creation of the diffusion matrix%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sc2=rc4key(DK(end-16:end));
% outd=prga( sc2,(h^2)/4);
% A=reshape(outd,h/2,h/2);
% In=eye(h/2,h/2);
% if (kindd==0)
% G=[A A+In; A-In A ];
% else
%  A=mod(A,2);
%  G=[A        bitxor(A,In) ; bitxor(A,In) A];      
% end