I have this program to turn in for an assignment, and need to know if it is indented properly and I also get some ascii symbols appear instead of the actual letters on the output side. Can anyone tell me if they see an issue, and if so what line?
THANKS
Code:
/*Author: John Puskar Description: Project 4
Date: December 10, 2012 */
#pragma warning( disable:4996)
#include<stdio.h>
//for small letters only
int FindGCD(int no1,int no2);
int InvEuclid(int a,int N) {
int r0,r1,r2,q1,x0,x1,x2;
r0=N;
r1=a;
x0=1;
r2=r0%r1;
q1=r0/r1;
x1=-q1;
while (r2){
r0=r1;
r1=r2;
q1=r0/r1;
r2=r0%r1;
x2=x0-(q1*x1);
x0=x1;x1=x2;
}
if (x0>0)
return x0;
else
return (N+x0);
}
int main () {
char small[27],data[100],cipher[100],decipher[100];
int i=0,j=0,k1,k2,flag,count=0,temp;
for (i;i<26;i++){
small[i] = 'a'+i;
//printf("%c",small[i]);
}
printf("please enter the text message to encrypt\n");
scanf("%[^\n]s",data);
fflush(stdin);
//ask user to provide atleast two mapping
i=0;
while(1){
printf("\nplease enter the first key 1<k1<26 such that gcd of (k2,26)=1\n"); //first key is: 19
scanf("%d",&k1);
printf("\nplease enter the second key 1<k2<26\n "); // second key is: 4
scanf("%d",&k2);
flag =FindGCD(k1,26);
if (flag==1)
break;
else
printf("\nPlease reenter the keys");
}
//ciphere the text and show it to the user
while (1){
temp = data[i];
// printf("g%d",flag);
if (temp==0)
break;
flag= data[i]-'a';
if (flag>=0 && flag <=25){
flag=(flag*k1) +k2;
//printf("g%d",flag);
flag= flag%26;
cipher[i]=small[flag];
}
else{
cipher[i]=data[i];
}
count++;
i++;
}
printf("\nthe encrypted string is\n ");
while(j<i){
printf("%c",cipher[j]);
j++;
}
printf("\n");
//decipher the ciphered text
// printf("c%d\n",count);
k1= InvEuclid(k1,26);
//printf("%d",k1);
i=0;
for(i=0;i<count;i++){
flag= cipher[i]-'a';
//printf("%d",flag);
if (flag>=0 && flag <=25){
flag=(flag-k2)*k1;
//printf("g%d",flag);
flag= flag%26;
decipher[i]=small[flag];
}
else{
decipher[i]=data[i];
}
}
j=0;
printf("\nthe dencrypted string is\n ");
while(j<i){
printf("%c",decipher[j]);
j++;
}
printf("\n");
return 0;
}
int FindGCD(int no1,int no2){
int divd,divs,r;
if (no1>no2){
divd=no1;
divs = no2;
}
else{
divd= no2;
divs=no1;
}
r = divd%divs;
while (r>0){
divd= divs;
divs= r ;
r= divd%divs;
if (r==1){
return 1;
}
}
if (r==0){
return divs;
}
return 0;
}