首页 > 编程知识 正文

随机数和伪随机数的区别,伪随机数生成算法

时间:2023-05-06 05:31:31 阅读:119873 作者:3243

//# include ' myrandom.h ' # includecstdlib # includeiostreamusingnamespacestd; //void编码器(unsignedchardata [ ],int len,unsigned long Key ); 语音显示(unsignedlonglongdata [ ],int len; //void编码器(unsignedchardata [ ],int len,unsigned long Key ); class crypter { public : void setkey (unsigned long key ) {myKey=key; } voidencryptr (unsignedlonglongdata [ ],int len ) ) Srand ) mykey; //int i=rand (; for(intI=0; i len; I () {data[i] ^=rand ); } voiddecryptr (unsignedlonglongdata [ ],int len ) ) encryptr(data,len ); }private://TRandom rand; 无符号长键; (; # endif # includeiostreamusingnamespacestd; # include ' crypter.h ' # include ' myrandom.h ' # includecstdlibvoiddisplay (unsignedlonglongdata (,int len ) for ) ) i len; I ) {cout data[i] ' * '; }cout endl; //第一题//voidcoder(unsignedchardata[],int len,unsigned long Key ) {static TRandom staticRand; saticrand.seed(key; for(intI=0; i len; I ) data [ I ] ^=静态rand.integer (0,1024 ); ()//第二题/*voidcoder(unsignedchardata[],int len,TRandom bas,unsigned long Key ) srand ) key; for(intI=0; i len; I () {data[i] ^=rand ); } */# include iostream # includecstdlibusingnamespacestd; # include ' crypter.h '//# include ' myrandom.h ' int main () {const int len=170; 无符号长龙数据[ len ]; memset (数据,0,sizeof )数据); data[1]=1; data[2]=1; //Fibonaccisequencefor(intI=3; i len; I ) {data[i]=data[i-1] data[i-2]; }Crypter a; a .安全(rand ) ); cout '加密前: '; 显示(data,len ); cout '加密后: '; a.encryptr (数据,len ); 显示(data,len ); cout '解密后: '; a.decryptr (数据,len ); 显示(data,len ); 返回0; (/*第一题cout“加密前”显示(数据、lena ); cout endl; cout '加密后'; 编码程序(data、lena、123456789; 显示(数据、lena ); cout endl; cout '解密后: '; 编码程序(data、lena、123456789; 显示(数据、lena ); cout endl; //第二题/*TRandom rand; cout '加密前'; 显示(数据、lena ); cout endl; cout '加密后'; 编码程序(data、lena、rand、123456789; 显示(数据、lena ); cout endl; cout '解密后: '; 编码程序(data、lena、rand、123456789; 显示(数据、lena ); cout endl; */

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。