I wanted to improve a crypter from internet. I found it poor and modified it.
Do you like it?
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
//Simple C program to encrypt and decrypt a string
#include <stdio.h>
int main()
{
int scnt;
int scnt2;
int i, x;
char str[512];
printf("\nCrypter ver0.1\n");
printf("\nYou need enter or create two keys for security\nWrite they in safe place\nTHIS PROGRAM CONTAINS BUGS");
printf("\nPlease enter a string:\t");
gets(str);
printf("\nPlease choose following options:\n");
printf("1 = Encrypt the string.\n");
printf("2 = Decrypt the string.\n");
scanf("%d", &x);
printf("Create or Provide Exist Key:\n");
scanf("%d", &scnt);
printf("Create or Provide Exist Second Key:\n");
scanf("%d", &scnt2);
//using switch case statements
switch(x)
{
case 1:
for(i = 0; (i < 512 && str[i] != '\0'); i++)
str[i] = str[i] + scnt - scnt2; //the key for encryption is 3 that is added to ASCII value
printf("\nYou Encrypted String! You now in safe");
printf("\nEncrypted string: %s\n", str);
break;
case 2:
for(i = 0; (i < 512 && str[i] != '\0'); i++)
str[i] = str[i] - scnt + scnt2; //the key for encryption is 3 that is subtracted to ASCII value
printf("\nYou Decrypted String!\n");
printf("\nDecrypted string: %s\n", str);
break;
default:
printf("\nYou entered wrong number Select from 1 to 2\n");
}
return 0;
}
yes I know it contains so many bugs but I tested it on a long string and it worked (bugs are: 1. spaces don't work 2. in some keys it halts 3. unstable) but it decrypts fully without mistakes (tested around 50+ keys).
I made it so hard to hack even if you have source of program because my crypter uses 2 keys what makes it more hard to hack!
scnt - scnt2
, a single number. You have the user remember two numbers, but provide no better encryption than with a single number. This is typically called the "Cesar cipher", the simplest and oldest cipher in the books. Decoding the text with all possible keys and seeing which of the results makes sense is trivial. Do not rely on this cipher for anything. \$\endgroup\$