www.pudn.com > VC_RSA.rar > CDSA.cpp


#include "StdAfx.h" 
#include "CCommon.h" 
#include "CDSA.h" 
 
CString deletestr(CString str,int count) 
{ 
	int tlen=str.GetLength(); 
	return str.Right(tlen-count); 
} 
 
void zeronetochar8(char &g,CString x) 
{ 
	g=(char)(Binstr_To_Int10(x)); 
} 
 
void zeronetochar6(int &g,CString x) 
{ 
	g=Binstr_To_Int10(x); 
} 
 
void initialize8(CString trans[]) 
{ 
   int c1, c2, c3, c4, c5, c6, c7, c8; 
   CString x; 
   char g; 
   for(c1=0;c1<2;c1++) 
      for(c2=0;c2<2;c2++) 
         for(c3=0;c3<2;c3++) 
            for(c4=0;c4<2;c4++) 
               for(c5=0;c5<2;c5++) 
                  for(c6=0;c6<2;c6++) 
                     for(c7=0;c7<2;c7++) 
                        for(c8=0;c8<2;c8++) 
                        { 
                           x=char(c1+48) + char(c2+48) + char(c3+48) + char(c4+48) + char(c5+48) + char(c6+48) + char(c7+48) + char(c8+48); 
                           zeronetochar8(g, x); 
                           trans[g]= x; 
                        } 
} 
 
 
void initialize6(CString trans[]) 
{ 
   int c1, c2, c3, c4, c5, c6; 
   CString x; 
   int g; 
   for(c1=0;c1<2;c1++) 
      for(c2=0;c2<2;c2++) 
         for(c3=0;c3<2;c3++) 
            for(c4=0;c4<2;c4++) 
               for(c5=0;c5<2;c5++) 
                  for(c6=0;c6<2;c6++) 
                  { 
                     x=char(c1+48) + char(c2+48) + char(c3+48) + char(c4+48) + char(c5+48) + char(c6+48); 
                     zeronetochar6(g, x); 
                     trans[chr64[g]]= x; 
                  } 
} 
 
void Convert8to6bit(CString str8,CString &str6) 
{ 
   CString temp; 
   CString trans[256]; 
   unsigned i,len6,tlen; 
   int g; 
 
   initialize8(trans); 
   temp="";tlen=str8.GetLength(); 
   for(i=0;i=0)) 
	   GIntstr=deletestr(GIntstr,1); 
 
   if(GIntstr[0]=='-') 
   { 
	  GIntstr=deletestr(GIntstr,1); 
      p=negative; 
   } 
   else p=positive; 
   while((GIntstr[0]=='0')&&(GIntstr.GetLength()>1)) 
	   GIntstr=deletestr(GIntstr,1); 
 
   temp2=new TGInt; 
   temp2->next=NULL; 
   if((GIntstr.GetLength()%4)==0) 
   { 
 
      temp2->value=atol(GIntstr.Mid(0,4)); 
      GIntstr=deletestr(GIntstr,4); 
   } 
   else 
   { 
      temp2->value=atol(GIntstr.Mid(0,(GIntstr.GetLength()%4))); 
	  GIntstr=deletestr(GIntstr,(GIntstr.GetLength()%4)); 
   } 
 
   while(GIntstr.GetLength()>0) 
   { 
      temp1=new TGInt; 
      temp1->next=temp2; 
      temp2->prev=temp1; 
      temp1->value=atol(GIntstr.Mid(0,4)); 
      GIntstr=deletestr(GIntstr,4); 
      temp2=temp1; 
   } 
 
   temp2->prev=NULL; 
   temp2->sign=p; 
   GInt=temp2; 
} 
 
void GIntToDecStr(CString GIntstr, TGInt *GInt) 
{ 
   CString s; 
   Tsign p; 
 
   GIntstr=""; 
   p=GInt->sign; 
 
   s=CString(GInt->value); 
   while(s.GetLength()<4) 
	   s='0' + s; 
   GIntstr= s + GIntstr; 
   while(GInt->next!=NULL) 
   { 
      GInt= GInt->next; 
      s=CString(abs(GInt->value)); 
      while(s.GetLength()<4) s= '0' + s; 
      GIntstr = s + GIntstr; 
   } 
 
   while((GIntstr[0]=='0')&&(GIntstr.GetLength()>1)) 
      GIntstr=deletestr(GIntstr,1); 
 
   if(p==negative) 
	   GIntstr = '-' + GIntstr; 
}