C examples for Data Structure:Encrypt Decrypt
Implement a cryptographic system using the Reverse cipher method.
#include <stdio.h> #include <string.h> char *msgOriginal = "this is a test"; char msgEncrypt[100]; char msgDecrypt[100]; int intChoice, length; void encryptMsg() { int i, j;// w w w . j av a2 s .c o m length = strlen(msgOriginal); j = length - 1; for (i = 0; i < length; i++) { msgEncrypt[j] = msgOriginal[i] ; j--; } msgEncrypt[length] = '\0'; printf("\nEncrypted Message: %s", msgEncrypt); } void decryptMsg() { int i, j; fflush(stdin); printf("Enter the Message to be Decrypted (upto 100 characters): \n"); gets_s(msgEncrypt); length = strlen(msgEncrypt); j = length - 1; for (i = 0; i < length; i++) { msgDecrypt[j] = msgEncrypt[i] ; j--; } msgDecrypt[length] = '\0'; printf("\nDecrypted Message: %s", msgDecrypt); } void main() { encryptMsg(); decryptMsg(); }