From 06f6db0793e2866174627dceef0127ca54bcf2c4 Mon Sep 17 00:00:00 2001 From: Minhajul Hossain <38182673+minnonymous@users.noreply.github.com> Date: Wed, 30 Oct 2019 21:49:11 +0530 Subject: [PATCH] Create enc.c --- enc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 enc.c diff --git a/enc.c b/enc.c new file mode 100644 index 0000000..9d6276f --- /dev/null +++ b/enc.c @@ -0,0 +1,39 @@ +//Simple C program to encrypt and decrypt a string + +#include + +int main() +{ + int i, x; + char str[100]; + + 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); + + //using switch case statements + switch(x) + { + case 1: + for(i = 0; (i < 100 && str[i] != '\0'); i++) + str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value + + printf("\nEncrypted string: %s\n", str); + break; + + case 2: + for(i = 0; (i < 100 && str[i] != '\0'); i++) + str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value + + printf("\nDecrypted string: %s\n", str); + break; + + default: + printf("\nError\n"); + } + return 0; +}