I don't know if any of you have read Digital fortress by Dan Brown, but he describes an ancient method of encrypting messages by using a square.
4 letters: test
they would be displayed like this:
T E
S T
and the encrypted message would be this: TSET.
I wanted to create a tool that would encrypt and decrypt these messages for me.
This is what I have so far, and it works. The decrypter will come later, this is simply the basis for the program.
note:the code only works if you enter in 4 letters or less. It will be updated however to accept up to 100 characters.
I'm sorry, I don't like comments. I'm too lazy :p ( I know, I know...bad habit).
Any questions or suggestions would be welcome.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
int length, x, difference;
char input[144];
printf("Enter a phrase to be encrypted:");
putchar('\n');
gets(input);
length = strlen(input);
if(length <=4)
{
if(length > 0 && length < 4)
{
difference = 4 - length;
for(x=0;x<difference;x++)
{
strcat(input,"*");
}
length = strlen(input);
}
for(x=0;x<length;x++)
{
if(!isalnum(input[x]))
{
input[x] = '*';
}
}
printf("\nHere is you encrypted text: %c%c%c%c", input[0],input[2],input[1],input[3]);
}
return(0);
}