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^d if c=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();
}
Member Avatar for iamthwee

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.

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^d if c=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();
}

Hi there,
what are you trying to do with your programme? To find d? I may not be farmiliar with your programme but if I know what you are trying to achieve, I may be able to help. I am a Ph.D student at Jomo Kenyatta University of Agriculture and Technology, Kenya and I am working on non-factor methods of breaking the RSA code. I hope to hear what you are trying out on your end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.