⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsasimple.txt

📁 RSA加密解密算法的最简单的C实现的源代码。如果你不想看太复杂的RSA算法
💻 TXT
字号:
  #include   iostream.h   
  #include   conio.h   
  #include   math.h   
  #include   stdlib.h   
  #include   string.h   
    
  int   Transform(int   m,int   k,int   n);   
  int   IsRelativelyPrime(int   a,int   b);   
  int   IsPrime(int   a);   
    
  void   main()   
  {   
  int   X,Y,e,d,n,En,p,q;   
    
  couttSimple   Demo   of   RSA   Algorithmnn;   
  coutPlease   enter   the   value   of   p   ;   
  cinp;   
  while(!IsPrime(p))   
  {   
  coutError!   p   should   be   prime   ;   
  cinp;   
  }   
    
  coutPlease   enter   the   value   of   q   ;   
  cinq;   
  while(!IsPrime(q))   
  {   
  coutError!   q   should   be   prime   ;   
  cinq;   
  }   
    
  coutnCalculating   n   and   ф(n)...endl;   
  n=pq;   
  En=(p-1)(q-1);   
  coutn   =   n   and   ф(n)   =   Enendl;   
    
  coutendlPlease   enter   the   value   of   e   ;   
  cine;   
  while   (!IsRelativelyPrime(e,En))   
  {   
  coute   should   be   relatively   prime   to   n   ;   
  cine;   
  }   
  coutCalculating   d...endl;   
  d=1;   
  while   (((ed)%En)!=1)   d++;   
  cout   d   =         d      endl;   
    
  coutendlPlease   enter   the   value   of   Xendl;   
  cinX;   
  while   (X=nX=0)   
  {   
  cout   aX   should   be   within   0   and   n      ;   
  cinX;   
  }   
    
  coutEncrypting   message...endl;   
  Y=Transform(X,e,n);   
  coutCipher   Y   =   Yendl;   
    
  coutDecrypting   cipher...endl;   
  X=Transform(Y,d,n);   
  coutX   =   Xendl;   
  coutnPress   any   key   to   quit.endl;   
  getch();   
  }   
    
  int   Transform(int   m,int   k,int   n)   
  {   
  long   int   r=1;   
  char   bk[16];   
  itoa(k,bk,2);   
    
  for   (unsigned   int   i=0;istrlen(bk);i++)   
  {   
  r=(rr)%n;   
  if   (bk[i]   ==   '1')   
  {   
                          r=(rm)%n;   
  }   
  }   
  return   r;   
  }   
    
  int   IsRelativelyPrime(int   a,int   b)   
  {   
  for(int   i=2;i=sqrt(abab);i++)   
  if   ((a%i   ==   0)&&(b%i==0))   
  return   0;   
  return   1;   
  }   
    
  int   IsPrime(int   a)   
  {   
  for(int   i=2;i=sqrt(a);i++)   
  if(a%i==0)   return   0;   
  return   1;   
  }   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -