User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 392,092 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,897 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 919 | Replies: 1
Reply
Join Date: Jun 2007
Posts: 19
Reputation: praneeth_gunda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
praneeth_gunda's Avatar
praneeth_gunda praneeth_gunda is offline Offline
Newbie Poster

RSA Code

  #1  
Aug 5th, 2007
Hey Every Body can u PLease help me with this this is a code 4 RSA it is workin' for small values of {p,q,e} like {11,3,7} but it does'nt work for {11,17,7} Please help me at this POint even long double is not enough for storing the value of c[i]^d if c[i]=171 and d=23

#include<conio.h>
#include<math.h>
int funct(char p)
{
    int x;
    if(p>='a'&&p<='z')
      x=p-96;
    if(p>='A'&&p<='Z')
      x=p-64;
    return x;
}
void main()
{
  int i,p,q,n,z,e,s,c[30],p2[30],flag[30],tra;
  float l,d;
  long double x,y;
  unsigned long int div,div1;
  char pra[30];
  clrscr();
  printf("Enter the Values of P & Q");
  scanf("%d%d",&p,&q);
  n=p*q;
  z=(p-1)*(q-1);
  printf("Enter the Encryption key");
  scanf("%d",&e);
  l=1*(abs(z));
  d=ceil(l/e);
  printf("Enter The Plain Text");
  scanf("%s",pra);
for(i=0;i<strlen(pra);i++)
{
flag[i]=0;
if(pra[i]>='a'&&pra[i]<='z')
  flag[i]=1;
else
  continue;
}
  printf("Encryption\n");
  for(i=0;i<strlen(pra);i++)
  {
     s=funct(pra[i]);
     x=pow(((long double)s),((long double)e));
     div=(unsigned long int)x;
     c[i]=div%n;
     printf("%d  ",c[i]);
  }
  printf("\nDecryption\n");
  for(i=0;i<strlen(pra);i++)
  {
     tra=c[i];
    y=pow(((long double)tra),((long double)d));
     div1=(unsigned long int)y;
     p2[i]=div1%n;
     if(flag[i]==0)
       printf("%c   ",(p2[i]+64));
     else
	printf("%c  ",(p2[i]+96));
  }
  getch();
}
Praneeth Kumar
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,668
Reputation: iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice iamthwee is just really nice 
Rep Power: 17
Solved Threads: 298
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: RSA Code

  #2  
Aug 5th, 2007
There are many things wrong with your code...

That's before we even get into the rsa algorithm, which probably needs a big num library to work effectively.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 12:42 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC