亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ecc.c

?? C語言
?? C
?? 第 1 頁 / 共 5 頁
字號:
	if((chlong>=7)&&(chlong%7!=0))        //剩余字符的存放
	{
		if(chlong%7 < 4)           //剩余字符少余4個時,只需一個mp_digit單元存放
		{
			for(j=chlong-1;j>=i;j--)
			{
			   *temp |= (mp_digit)(ch[j] & 255);
               *temp <<= (mp_digit)CHAR_BIT;
			}
			*temp >>= (mp_digit)8;
			a->used=chlong*2/7+1;
		}
		else
		{                       //剩余字符不小于4個時,需兩個mp_digit單元存放
			i+=4;
            *temp |= (mp_digit)(ch[i-1] & yy);
		    *temp <<= (mp_digit)CHAR_BIT;
            *temp |= (mp_digit)(ch[i-2] & 255);
		    *temp <<= (mp_digit)CHAR_BIT;
            *temp |= (mp_digit)(ch[i-3] & 255);
		    *temp <<= (mp_digit)CHAR_BIT;
            *temp++ |= (mp_digit)(ch[i-4] & 255); //存放被切分的字符的低四位

            
            for(j=chlong-1;j>=i;j--)
			{  
			   *temp |= (mp_digit)(ch[j] & 255);
			   *temp <<= (mp_digit)CHAR_BIT;			                
			}
            *temp >>= (mp_digit)4;
            *temp |= (mp_digit)((ch[i-1] & 255) >> 4);  //存放被切分的字符的高四位
            
			a->used=chlong*2/7+2;
		}

	}
	else
	{
	   a->used=chlong*2/7;
	}
	return MP_OKAY;
}


void Ecc_encipher(mp_int *qx,mp_int *qy, mp_int *px, mp_int *py,mp_int *a,mp_int *p){

	mp_int mx, my;
	mp_int c1x, c1y;
	mp_int c2x, c2y;
    mp_int r;
	mp_int tempx, tempy;
    bool zero=false;
    FILE *fp,*fq;
	int i;
    char miwenx[280]={0};
    char miweny[280]={0};
	char stemp[650]={0};


	mp_init(&mx);
	mp_init(&my);
	mp_init(&c1x);
	mp_init(&c1y);
	mp_init(&c2x);
	mp_init(&c2y);
    mp_init(&r);
	mp_init(&tempx);
	mp_init(&tempy);

	GetPrime(&r, 100);

	char filehead[60],filefoot[20],filename[85]={0};
    cout<<"File to encrypt(e.g:  c:\\code\\ecc\\test  ):"<<endl;
	cin>>filehead;
    cout<<"Extension(e.g:  .txt  ):"<<endl;
	cin>>filefoot;
	strcpy(filename,filehead);
	strcat(filename,filefoot);
	

//打開要加密文件
	if((fp=fopen(filename,"rb"))==NULL)
	{
		printf("can not open the file!");
		exit(1);
	}

	unsigned int FileLong=0;//文件字符長度
	char ChTem;//臨時字符變
	int Frequency=0;
	int Residue=0;

    while( !feof(fp) )//找文件字符長度
	{
		ChTem = fgetc( fp );
		FileLong++;
	}
    --FileLong;


	Frequency = FileLong/EN_LONG;
	Residue = FileLong%EN_LONG;

	int enlongtemp=EN_LONG/2;
	//printf("%d\n",Frequency);  
	//printf("%d\n",Residue);  

	char filemi[85];
	strcpy(filemi,filehead);
	strcat(filemi,"en");
	strcat(filemi,filefoot);
    

 //打開保存密文文件
    if((fq=fopen(filemi,"wb"))==NULL)
	{
		 printf("can not open the file!\n");
		 exit(1);
	}

    printf("\nencrypting...\n");


	rewind(fp);
	for(i=0; i<Frequency; i++)
	{   
  
	    fread(miwenx,1,enlongtemp,fp);//讀入字符串
	    miwenx[enlongtemp]=char(255);

		fread(miweny,1,enlongtemp,fp);//讀入字符串
	    miweny[enlongtemp]=char(255);

        putin(&mx, miwenx,enlongtemp+1);//文件存入 		
		putin(&my, miweny,enlongtemp+1);//文件存入

	    Ecc_points_mul(&c2x,&c2y,px,py,&r,a,p);//加密
	    Ecc_points_mul(&tempx,&tempy,qx,qy,&r,a,p); 
	    Two_points_add(&mx,&my,&tempx,&tempy,&c1x,&c1y,a,zero,p);

        //保存密文      
	    chmistore(&c1x,fq); 
		chmistore(&c1y,fq);
		chmistore(&c2x,fq);
		chmistore(&c2y,fq);

	}
	//剩余字符處理
	if ( Residue > 0)
	{
	     if (Residue <= enlongtemp ) 
		{
			fread(miwenx,1,Residue,fp);//讀入字符串
			miwenx[Residue]=char(255);
     
			putin(&mx, miwenx,Residue+1);//文件存入 

			mp_zero(&my);
        
		}
		else
		{

			fread(miwenx,1,enlongtemp,fp);//讀入字符串
			miwenx[enlongtemp]=char(255);
        

			fread(miweny,1,Residue-enlongtemp,fp);//讀入字符串
			miweny[Residue-enlongtemp]=char(255);

			 putin(&mx, miwenx,enlongtemp+1);//文件存入 

			putin(&my, miweny,Residue-enlongtemp+1);//文件存入 
		}

		Ecc_points_mul(&c2x,&c2y,px,py,&r,a,p);//加密

	    Ecc_points_mul(&tempx,&tempy,qx,qy,&r,a,p); 

        
		Two_points_add(&mx,&my,&tempx,&tempy,&c1x,&c1y,a,zero,p);

	 
        //保存密文      
	    chmistore(&c1x,fq); 

		chmistore(&c1y,fq);

		chmistore(&c2x,fq);

		chmistore(&c2y,fq);  
	}

	
		cout<<"\nok!encrypted!"<<endl;
	    cout<<"Saved in binary"<<endl;
	    cout<<"Patch:  "<<filemi<<endl ;


	    fclose(fq);
        fclose(fp);
        mp_clear(&mx);
		mp_clear(&my);
	    mp_clear(&c1x);
	    mp_clear(&c1y);
	    mp_clear(&c2x);
	    mp_clear(&c2y);
        mp_clear(&r);
	    mp_clear(&tempx);
		mp_clear(&tempy);
     

}

//取密文

int miwendraw(mp_int *a,char *ch,int chlong)
{
    mp_digit *temp;
    int i,j,res;

    if(a->alloc<chlong/4)
	{
		if((res=mp_grow(a,chlong/4))!=MP_OKAY)
			return res;
	}

	a->alloc=chlong/4;
    a->sign=0;
	mp_zero(a);
	temp=a->dp;
	i=0;

	for(j=0;j<chlong/4;j++)
	{
		i+=4;
		*temp |= (mp_digit)(ch[i-4] & 255);
		*temp <<= (mp_digit)CHAR_BIT;
        *temp |= (mp_digit)(ch[i-3] & 255);
		*temp <<= (mp_digit)CHAR_BIT;
        *temp |= (mp_digit)(ch[i-2] & 255);
		*temp <<= (mp_digit)CHAR_BIT;
        *temp++ |= (mp_digit)(ch[i-1] & 255); 
	}
    a->used=chlong/4;
    return MP_OKAY;
}

//實現將mp_int數a中的比特串還原為字符串并賦給字符串ch:
int chdraw(mp_int *a,char *ch)
{
	int i,j;
	mp_digit *temp,xx,yy;

	temp=a->dp;
	i=0;
	yy=(mp_digit)255;  //用于位與運算,取八位比特串
	xx=(mp_digit)15;  //用于位與運算,取四位比特串

	for(j=0;j<a->used/2;j++)  //以兩個單元為循環,把兩個單元的比特串賦給7個字符
	{
		i+=7;
        ch[i-4]=(char)(*++temp & xx);
        ch[i-3]=(char)((*temp >> (mp_digit)4) & yy);	
		ch[i-2]=(char)((*temp >> (mp_digit)12) & yy);
        ch[i-1]=(char)((*temp-- >> (mp_digit)20) & yy);

		ch[i-7]=(char)(*temp & yy);
		ch[i-6]=(char)((*temp >> (mp_digit)8) & yy);
		ch[i-5]=(char)((*temp >> (mp_digit)16) & yy);
		ch[i-4] <<= 4;
		ch[i-4]+=(char)((*temp++ >> (mp_digit)24) & xx);
		temp++;
	}
	if(a->used%2!=0)  //剩于一個單元的處理
	{
		ch[i++] = (char)(*temp & yy);
		ch[i++] = (char)((*temp >> (mp_digit)8) & yy);
		ch[i++] = (char)((*temp >> (mp_digit)16) & yy);
	}
	--i;
    while(int(ch[i]&0xFF) != 255 && i>0) i--;
	return i;
   
}

void Ecc_decipher(mp_int *k, mp_int *a,mp_int *p){

	mp_int c1x, c1y;
	mp_int c2x, c2y;
    mp_int tempx, tempy;
	mp_int mx, my;
    mp_int temp;

	mp_init(&temp);
	mp_init(&c1x);
	mp_init(&c1y);
    mp_init(&c2x);
	mp_init(&c2y);
	mp_init(&tempx);
	mp_init(&tempy);
    mp_init(&mx);
	mp_init(&my);

	mp_int tempzero;
	mp_init(&tempzero);

    int i, kk;
	char stemp[700]={0};
    FILE *fp,*fq;
    bool zero=false;


	char filehead[60],filefoot[20],filename[85]={0};
    cout<<"File to decrypt(e.g:  c:\\code\\ecc\\testen  ):"<<endl;
	cin>>filehead;
    cout<<"Extension(e.g:  .txt  ):"<<endl;
	cin>>filefoot;
	strcpy(filename,filehead);
	strcat(filename,filefoot);

    printf("\ndecrypting\n");

    if((fp=fopen(filename,"rb"))==NULL)
	{
		 printf("can not open the file!");
		 exit(1);
	}
 
   //打開保存解密結果文件
    char filemi[80];
	strcpy(filemi, filehead);
	strcat(filemi, "de");
    strcat(filemi, filefoot);

    if((fq=fopen(filemi,"wb"))==NULL)
	{
		 printf("can not open the file!");
		 exit(1);
	}


	rewind(fp);
    while(!feof(fp))
	{
         i=0;
		 while(1)
		{
		     stemp[i]=fgetc(fp);
		     if(i%4==0)
			{
                 if(int(stemp[i]&0xFF) == 255 ) goto L1;
			}
		    i++;
		}
		     
L1:     miwendraw(&c1x, stemp, i);
         i=0;
		 while(1)
		{
		     stemp[i]=fgetc(fp);
		     if(i%4==0)
			{
                 if(int(stemp[i]&0xFF) == 255 ) goto L2;
			}
		    i++;
		}
		     
L2:     miwendraw(&c1y, stemp, i);
	     i=0;
		 while(1)
		{
		     stemp[i]=fgetc(fp);
		     if(i%4==0)
			{
                 if(int(stemp[i]&0xFF) == 255 ) goto L3;
			}
		    i++;
		}
		     
L3:     miwendraw(&c2x, stemp, i);
	            i=0;
		 while(1)
		{
		     stemp[i]=fgetc(fp);
		     if(i%4==0)
			{
                 if(int(stemp[i]&0xFF) == 255 ) goto L4;
			}
		    i++;
		}
		     
L4:     miwendraw(&c2y, stemp, i);

	    mp_zero(&tempzero);
        if(mp_cmp(&c1x, &tempzero)==0) break;

        Ecc_points_mul(&tempx, &tempy, &c2x, &c2y, k, a, p); 

        mp_neg(&tempy, &temp);
        Two_points_add(&c1x,&c1y,&tempx,&temp,&mx,&my,a,zero,p);
	    
		int chtem;
	    chtem=chdraw(&mx,stemp);//從ming中取出字符串
     

		//保存解密結果
    
		for(kk=0;kk<chtem;kk++)
		{
	         fprintf(fq,"%c",stemp[kk]);
			       
		}

	    chtem=chdraw(&my,stemp);//從ming中取出字符串
    
	         
	     //保存解密結果
		  for(kk=0;kk<chtem;kk++)
		{
	          fprintf(fq,"%c",stemp[kk]);
			
		}
		  
	    
	}

   	cout<<"\nok!decrypted!"<<endl;
	cout<<"Patch:  "<<filemi<<endl;

    fclose(fq);
    fclose(fp);
    mp_clear(&c1x);
	mp_clear(&c1y);
	mp_clear(&c2x);
	mp_clear(&c2y);
    mp_clear(&tempx);
	mp_clear(&tempy);
	mp_clear(&mx);
	mp_clear(&my);
    mp_clear(&temp);


}



/*以下為libtomath庫*/
#ifdef BN_MP_INIT_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
 */

/* init a new mp_int */
int mp_init (mp_int * a)
{
  int i;

  /* allocate memory required and clear it */
  a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * MP_PREC);
  if (a->dp == NULL) {
    return MP_MEM;
  }

  /* set the digits to zero */
  for (i = 0; i < MP_PREC; i++) {
      a->dp[i] = 0;
  }

  /* set the used to zero, allocated digits to the default precision
   * and sign to positive */
  a->used  = 0;
  a->alloc = MP_PREC;
  a->sign  = MP_ZPOS;

  return MP_OKAY;
}
#endif

/* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
/* $Revision: 1.4 $ */
/* $Date: 2006/12/28 01:25:13 $ */



#ifdef BN_MP_TORADIX_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
 *
 * LibTomMath is a library that provides multiple-precision
 * integer arithmetic as well as number theoretic functionality.
 *
 * The library was designed directly after the MPI library by
 * Michael Fromberger but has been written from scratch with
 * additional optimizations in place.
 *
 * The library is free for all purposes without any express
 * guarantee it works.
 *
 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
 */

/* stores a bignum as a ASCII string in a given radix (2..64) */
int mp_toradix (mp_int * a, char *str, int radix)
{
  int     res, digs;
  mp_int  t;
  mp_digit d;
  char   *_s = str;

  /* check range of the radix */
  if (radix < 2 || radix > 64) {
    return MP_VAL;
  }

  /* quick out if its zero */
  if (mp_iszero(a) == 1) {
     *str++ = '0';
     *str = '\0';
     return MP_OKAY;
  }

  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
    return res;
  }

  /* if it is negative output a - */
  if (t.sign == MP_NEG) {
    ++_s;
    *str++ = '-';
    t.sign = MP_ZPOS;
  }

  digs = 0;
  while (mp_iszero (&t) == 0) {
    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
      mp_clear (&t);
      return res;
    }
    *str++ = mp_s_rmap[d];
    ++digs;
  }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线观看www91| 日韩av电影一区| 国产aⅴ精品一区二区三区色成熟| 最新中文字幕一区二区三区 | 麻豆精品久久精品色综合| 8v天堂国产在线一区二区| 亚洲成人动漫av| 欧美精品黑人性xxxx| 欧美aaa在线| 久久精品视频一区| av男人天堂一区| 亚洲一区在线看| 欧美zozo另类异族| 成人av网站在线观看免费| 亚洲综合久久av| 精品日产卡一卡二卡麻豆| 成人免费va视频| 亚洲一区二区三区激情| 日韩精品资源二区在线| 成人污污视频在线观看| 亚洲无人区一区| 久久久国产精品麻豆| 91免费视频大全| 奇米777欧美一区二区| 中文字幕免费不卡在线| 欧美日韩中字一区| 国产不卡视频一区二区三区| 亚洲美女电影在线| 精品国产一区二区三区久久影院 | 国产在线观看免费一区| 亚洲人成小说网站色在线| 欧美精品日韩综合在线| 国产成人福利片| 日韩成人免费看| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆 | 一区二区三区四区精品在线视频| 日韩一级二级三级| 99re亚洲国产精品| 麻豆成人久久精品二区三区红 | 成人国产免费视频| 美女在线一区二区| 亚洲精品成人在线| 久久久久久久综合狠狠综合| 欧美午夜一区二区三区免费大片| 韩国av一区二区三区四区| 洋洋成人永久网站入口| 久久精品视频在线免费观看| 日韩午夜中文字幕| 一本色道a无线码一区v| 成人性生交大片免费看在线播放 | 国产精品一区在线观看乱码| 国产91丝袜在线观看| 8v天堂国产在线一区二区| 日本sm残虐另类| 欧美成人国产一区二区| 不卡影院免费观看| 亚洲欧洲国产日韩| 97久久精品人人爽人人爽蜜臀| 日本一区二区电影| 久久久91精品国产一区二区精品| 狠狠色丁香久久婷婷综合丁香| 精品99久久久久久| 欧美日韩国产一区二区三区地区| 亚洲女与黑人做爰| 欧美国产精品一区| 久久久天堂av| 国产区在线观看成人精品 | 精品久久久久久亚洲综合网| 欧美精品一卡两卡| 欧美亚洲综合在线| 欧美日韩一卡二卡三卡| 在线免费观看视频一区| 色猫猫国产区一区二在线视频| 成人99免费视频| 99久久精品国产麻豆演员表| 99国产欧美久久久精品| 99精品热视频| 97精品久久久久中文字幕| 色综合久久中文字幕| 色婷婷久久久久swag精品| 91福利精品第一导航| 91久久精品网| 欧美视频一区二区| 欧美日韩国产高清一区二区| 91精品国产综合久久久蜜臀粉嫩| 91精品黄色片免费大全| 精品日韩在线观看| 国产亚洲欧美日韩日本| 国产精品久久久久久久浪潮网站| 国产精品热久久久久夜色精品三区| 中文字幕成人av| 亚洲欧美另类图片小说| 亚洲无人区一区| 久久99久久99| 丁香婷婷深情五月亚洲| 色成人在线视频| 91精品国产综合久久香蕉的特点| 日韩视频123| 国产日韩视频一区二区三区| 亚洲免费观看高清完整版在线 | 中文字幕一区免费在线观看| 亚洲精选视频在线| 无码av免费一区二区三区试看| 午夜视频一区二区| 狠狠色2019综合网| 99视频在线观看一区三区| 欧美日韩综合在线免费观看| 欧美精品一区二区三区很污很色的| 国产三级三级三级精品8ⅰ区| ㊣最新国产の精品bt伙计久久| 亚洲123区在线观看| 韩国中文字幕2020精品| 色哟哟一区二区| 日韩欧美国产1| 亚洲男人电影天堂| 免费不卡在线观看| 99热精品国产| 精品1区2区在线观看| 综合自拍亚洲综合图不卡区| 免费久久精品视频| 一本大道久久a久久精品综合| 91精品婷婷国产综合久久竹菊| 中文字幕不卡一区| 久久精品国产99国产| 97久久精品人人做人人爽50路| 日韩精品专区在线影院观看 | 欧美丰满一区二区免费视频| 久久久久久久久蜜桃| 亚洲综合一区二区三区| 国产传媒日韩欧美成人| 91精品久久久久久久91蜜桃| 亚洲丝袜自拍清纯另类| 国产九色sp调教91| 欧美一区二区三区免费视频| 亚洲欧洲日产国码二区| 国产精品一区二区在线看| 欧美日韩国产a| 日韩理论在线观看| 国产精品一区不卡| 中文字幕一区二区三| 精品一区二区三区蜜桃| 欧美日韩性生活| 亚洲免费观看视频| av在线一区二区三区| 久久久久久久一区| 极品瑜伽女神91| 在线电影国产精品| 亚洲国产综合人成综合网站| 99精品国产一区二区三区不卡| 精品av久久707| 久久国产视频网| 91麻豆精品国产91久久久久 | 日本中文字幕一区| 欧美三级视频在线| 亚洲狠狠爱一区二区三区| 在线免费观看一区| 亚洲综合色视频| 欧美色综合久久| 亚洲综合图片区| 欧美色成人综合| 亚洲.国产.中文慕字在线| 欧美三区在线视频| 亚洲国产成人va在线观看天堂| 色拍拍在线精品视频8848| 亚洲三级电影全部在线观看高清| 99精品国产91久久久久久| 最新中文字幕一区二区三区 | 亚洲图片欧美激情| 972aa.com艺术欧美| 亚洲精品国产精华液| 日本韩国欧美在线| 亚洲一区二区三区四区在线免费观看 | 91看片淫黄大片一级| 亚洲婷婷国产精品电影人久久| 91麻豆国产香蕉久久精品| 夜夜嗨av一区二区三区中文字幕| 日本精品一区二区三区高清 | 色女孩综合影院| 一区二区三区在线看| 在线观看av一区二区| 天天色综合成人网| 日韩一区二区三区视频在线| 国内精品国产三级国产a久久| 精品av久久707| 成人一道本在线| 一区二区免费看| 欧美精品久久天天躁| 狠狠色综合播放一区二区| 欧美国产精品一区二区三区| 91视频观看视频| 亚洲成a人v欧美综合天堂| 日韩欧美视频在线| 成人av电影在线| 日韩中文字幕av电影| 精品理论电影在线| 91色综合久久久久婷婷| 日韩精品每日更新| 欧美激情一区二区| 欧美日韩亚洲综合| 国产成人免费网站|