im a first year engg student. i need 2 make a report on cryptography and i need the source code in C for caeser cipher. as it so happens im not very good at c programming... please help
can u tell me wats wrong wid this program?
#include <stdio.h>
void encrypt(int shift);
int main(void)
{
int shift;
int decOrEnc;
printf("Amount of shifts: ");
scanf("%d", &shift);
if (shift < 0)
{
printf("Bad Input.");
return 0;
}
printf("Type 1 to encrypt or 0 to decrypt: ");
scanf("%d", &decOrEnc);
if (decOrEnc != 0 && decOrEnc !=1)
{
printf("Bad Input.");
return 0;
}
while(getchar() != '\n');
if (decOrEnc == 1)
encrypt(shift);
else
{
shift = -1 * shift;
encrypt(shift);
}
return 0;
}
void encrypt(int shift)
{
char ch;
printf("Please enter a string: ");
ch = getchar();
while(ch != '\n')
{
if (ch == ' ')
putchar(ch);
if(shift == 1)
putchar(ch + shift);
else
putchar(ch - shift);
}
ch = getchar();
}
putchar(ch);
}