<P>这个是.m文件的主文件 名为publickey.m<br>clear<br>fid=fopen('mydata','r');<br>F=fread(fid);<br>m=char(F');<br>s=length(m);<br>[v,t1]=find(m==13);[v,t2]=find(m==10);%pm为回车换行位置<br>rho=input('请输入随机变量相关参数rho:');<br>X0=input('请输入随机变量初值X0:');<br>N=input('请输入随机序列长度值N:');<br>L=input('请输入加密位置L:');<br>X=gaus_mar(X0,rho,N);<br>y=X(L:L+s-1);<br>[v1,g]=sort(y);<br>[v2,f]=sort(g);<br>c=m(g)<br>p=c(f)<br><br>这个是名为gngauss.m的文件<br>function [g1,g2]=gngauss(m,sgma)<br>if nargin == 0,<br> m=0;sgma=1;<br>elseif nargin == 1,<br> sgma=m; m=0;<br>end<br>u=rand;<br>z=sgma*(sqrt(2*log(1/(1-u))));<br>u=rand;<br>g1=m+z*cos(2*pi*u);<br>g2=m+z*sin(2*pi*u);<br><br><br>这是名为gaus_mar.m的文件<br>function [X]=gaus_mar(X0,rho,N)<br>for i=1:2:N<br> [Ws(i) Ws(i+1)]=gngauss;<br>end<br>X(1)=rho*X0+Ws(1);<br>for i=2:N<br> X(i)=rho*X(i-1)+Ws(i);<br>end<br> <br>用MATCOM在VC里翻译出来的程序是<br>这是g_publickey.cpp:<br><br> #include "matlib.h"<br> #pragma hdrstop<br> <br> #include "publickey.h"<br> <br> unsigned int mlibpr=mt_set_MT(0); // 1 if program is multithreaded, 0 otherwise.<br> <br> <br> int main() {<br> begin_scope<br> <br> initM(MATCOM_VERSION);<br> <br> #include "publickey.cpp"<br> <br> exitM();<br> return 0;<br> end_scope<br> }<br> <br>这是gaus_mar.cpp:<br>#include "matlib.h"<br> #pragma hdrstop<br> <br> #include "gaus_mar.h"<br> #include "gngauss.h"<br> <br> <br> <br> Mm gaus_mar(Mm X0, Mm rho, Mm N) {<br> begin_scope<br> X0.setname("X0"); rho.setname("rho"); N.setname("N"); <br> dMm(X); dMm(i_); dMm(i_gaus_mar_v0); dMm(Ws); dMm(lhs_0); dMm(lhs_1); dMm(i_gaus_mar_v1); <br> <br> #line 1 "d:/公开单钥/gaus_mar.m"<br> call_stack_begin;<br> #line 1 "d:/公开单钥/gaus_mar.m"<br> // nargin, nargout entry code<br> double old_nargin=nargin_val; if (!nargin_set) nargin_val=3.0;<br> nargin_set=0;<br> double old_nargout=nargout_val; if (!nargout_set) nargout_val=1.0;<br> nargout_set=0;<br> <br> // translated code<br> <br> #line 2 "d:/公开单钥/gaus_mar.m"<br>_ i_gaus_mar_v0 = colon(1.0,2.0,N); int i_gaus_mar_i0;<br> for (i_gaus_mar_i0=0;i_gaus_mar_i0<i_gaus_mar_v0.cols();i_gaus_mar_i0++) {<br> forelem(i_,i_gaus_mar_v0,i_gaus_mar_i0);<br> #line 3 "d:/公开单钥/gaus_mar.m"<br>_ /*[Ws(i_),Ws(i_+1.0)] = */gngauss(i_o,lhs_0,lhs_1); Ws(i_) = lhs_0; Ws(i_+1.0) = lhs_1;<br> #line 4 "d:/公开单钥/gaus_mar.m"<br> }<br> #line 5 "d:/公开单钥/gaus_mar.m"<br>_ X(1.0) = rho*X0+Ws(1.0);<br> #line 6 "d:/公开单钥/gaus_mar.m"<br>_ i_gaus_mar_v1 = colon(2.0,1.0,N); int i_gaus_mar_i1;<br> for (i_gaus_mar_i1=0;i_gaus_mar_i1<i_gaus_mar_v1.cols();i_gaus_mar_i1++) {<br> forelem(i_,i_gaus_mar_v1,i_gaus_mar_i1);<br> #line 7 "d:/公开单钥/gaus_mar.m"<br>_ X(i_) = rho*X(i_-1.0)+Ws(i_);<br> #line 8 "d:/公开单钥/gaus_mar.m"<br> }<br> <br> call_stack_end;<br> <br> // nargin, nargout exit code<br> nargin_val=old_nargin; nargout_val=old_nargout;<br> <br> // function exit code<br> X0.setname(NULL); rho.setname(NULL); N.setname(NULL); <br> return X;<br> end_scope<br> }<br> <br>这是gngauss.cpp:<br> #include "matlib.h"<br> #pragma hdrstop<br> <br> #include "gngauss.h"<br> <br> <br> Mm gngauss(Mm m, Mm sgma, i_o_t, Mm& g1__o, Mm& g2__o) {<br> begin_scope<br> m.setname("m"); sgma.setname("sgma"); <br> dMm(g1); dMm(g2); dMm(u); dMm(z); <br> <br> #line 1 "d:/公开单钥/gngauss.m"<br> call_stack_begin;<br> #line 1 "d:/公开单钥/gngauss.m"<br> // nargin, nargout entry code<br> double old_nargin=nargin_val; if (!nargin_set) nargin_val=2.0;<br> nargin_set=0;<br> double old_nargout=nargout_val; if (!nargout_set) nargout_val=2.0;<br> nargout_set=0;<br> <br> // translated code<br> <br> #line 2 "d:/公开单钥/gngauss.m"<br>_ if (istrue(nargin()==0.0)) {<br> #line 3 "d:/公开单钥/gngauss.m"<br>_ m = 0.0;<br> #line 3 "d:/公开单钥/gngauss.m"<br>_ sgma = 1.0;<br> #line 4 "d:/公开单钥/gngauss.m"<br> } else<br> #line 4 "d:/公开单钥/gngauss.m"<br> if (istrue(nargin()==1.0)) {<br> #line 5 "d:/公开单钥/gngauss.m"<br>_ sgma = m;<br> #line 5 "d:/公开单钥/gngauss.m"<br>_ m = 0.0;<br> #line 6 "d:/公开单钥/gngauss.m"<br> }<br> #line 7 "d:/公开单钥/gngauss.m"<br>_ u = rand();<br> #line 8 "d:/公开单钥/gngauss.m"<br>_ z = sgma*(msqrt(2.0*log(1.0/(1.0-u))));<br> #line 9 "d:/公开单钥/gngauss.m"<br>_ u = rand();<br> #line 10 "d:/公开单钥/gngauss.m"<br>_ g1 = m+z*cos(2.0*pi*u);<br> #line 11 "d:/公开单钥/gngauss.m"<br>_ g2 = m+z*sin(2.0*pi*u);<br> <br> call_stack_end;<br> <br> // nargin, nargout exit code<br> nargin_val=old_nargin; nargout_val=old_nargout;<br> <br> // function exit code<br> m.setname(NULL); sgma.setname(NULL); <br> g1__o=g1; g2__o=g2; <br> return x_M;<br> end_scope<br> }<br> <br> <br> Mm gngauss() {<br> begin_scope<br> double old_nargin=nargin_val; nargin_val=0.0; nargin_set=1;<br> double old_nargout=nargout_val; nargout_val=1.0; nargout_set=1;<br> dMm(m); dMm(sgma); dMm(g1__o); dMm(g2__o); <br> gngauss(m, sgma, i_o, g1__o, g2__o);<br> nargout_val=old_nargout;<br> nargin_val=old_nargin;<br> return(g1__o);<br> end_scope<br> }<br> <br> Mm gngauss(Mm m) {<br> begin_scope<br> double old_nargin=nargin_val; nargin_val=1.0; nargin_set=1;<br> double old_nargout=nargout_val; nargout_val=1.0; nargout_set=1;<br> dMm(sgma); dMm(g1__o); dMm(g2__o); <br> gngauss(m, sgma, i_o, g1__o, g2__o);<br> nargout_val=old_nargout;<br> nargin_val=old_nargin;<br> return(g1__o);<br> end_scope<br> }<br> <br> Mm gngauss(Mm m, Mm sgma) {<br> begin_scope<br> double old_nargin=nargin_val; nargin_val=2.0; nargin_set=1;<br> double old_nargout=nargout_val; nargout_val=1.0; nargout_set=1;<br> dMm(g1__o); dMm(g2__o); <br> gngauss(m, sgma, i_o, g1__o, g2__o);<br> nargout_val=old_nargout;<br> nargin_val=old_nargin;<br> return(g1__o);<br> end_scope<br> }<br> <br> Mm gngauss(i_o_t, Mm& g1__o, Mm& g2__o) {<br> begin_scope<br> double old_nargin=nargin_val; nargin_val=0.0; nargin_set=1;<br> double old_nargout=nargout_val; nargout_val=2.0; nargout_set=1;<br> dMm(m); dMm(sgma); <br> gngauss(m, sgma, i_o, g1__o, g2__o);<br> nargout_val=old_nargout;<br> nargin_val=old_nargin;<br> return x_M;<br> end_scope<br> }<br> <br> Mm gngauss(Mm m, i_o_t, Mm& g1__o, Mm& g2__o) {<br> begin_scope<br> double old_nargin=nargin_val; nargin_val=1.0; nargin_set=1;<br> double old_nargout=nargout_val; nargout_val=2.0; nargout_set=1;<br> dMm(sgma); <br> gngauss(m, sgma, i_o, g1__o, g2__o);<br> nargout_val=old_nargout;<br> nargin_val=old_nargin;<br> return x_M;<br> end_scope<br> }<br> <br><br>麻烦帮我看一下</P>
[此贴子已经被作者于2006-5-16 23:25:21编辑过]
|