| Jessehk |
May 27th, 2005 9:31 PM |
version 0.8 :D
:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define FALSE 0
#define TRUE !FALSE
int main()
{
int length, x, difference, choice, done, choice2,y;
char input[144];
done = FALSE;
while(!done)
{
printf("\n\n G R I D E N C R Y P T\n\n\n");
puts("-----------------------------------");
printf("\n\n1 = encrypt");
printf("\n2 = decrypt");
printf("\n3 = quit");
printf("\n\n\nEnter choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
break;
case 2:
break;
default:
break;
}
fflush(stdin);
if(choice==1) /* encrypt */
{
printf("\n E N C R Y P T O R\n\n\n");
printf("\nEnter 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]) && !ispunct(input[x]))
{
input[x] = '*';
}
}
printf("\nHere is you encrypted text: %c%c%c%c", input[0],input[2],
input[1],input[3]);
/*
0,1,
2,3,
*/
}
else if(length > 4 && length <=9)
{
if(length > 4 && length < 9)
{
difference = 9 - length;
for(x=0;x<difference;x++)
{
strcat(input,"*");
}
length = strlen(input);
}
for(x=0;x<length;x++)
{
if(!isalnum(input[x]) && !ispunct(input[x]))
{
input[x] = '*';
}
}
printf("\nHere is your encrypted text: %c%c%c%c%c%c%c%c%c", input[0],input[3],input[6],
input[1],input[4],input[7],
input[2],input[5],input[8]);
/*
0,1,2,
3,4,5,
6,7,8 ,
*/
}
else if(length > 9 && length <=16) /* if(length > 9 && length <=16) */
{
if(length > 9 && length < 16)
{
difference = 16 - length;
for(x=0;x<difference;x++)
{
strcat(input,"*");
}
length = strlen(input);
}
for(x=0;x<length;x++)
{
if(!isalnum(input[x]) && !ispunct(input[x]))
{
input[x] = '*';
}
}
printf("\nHere is your encrypted text: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", input[0],input[4],input[8],input[12],
input[1],input[5],input[9],input[13],
input[2],input[6],input[10],input[14],
input[3],input[7],input[11],input[15]);
/*
0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15
*/
}
}
else if(choice == 2)
{
printf("\n D E C R Y P T O R\n");
printf("\nEnter a phrase to be decrypted: ");
gets(input);
length = strlen(input);
if(length == 4)
{
for(x=0;x<length;x++)
{
if(!isalnum(input[x]) && !ispunct(input[x]))
{
input[x] = ' ';
}
}
for(y=0;y<length;y++)
{
if(input[y]=='*')
{
input[y] = ' ';
}
}
printf("\nHere is your decrypted text: %c%c%c%c", input[0],input[2],
input[1],input[3]);
/*
01
23
*/
}
else if(length == 9) /* if(length > 4 && length <=9) */
{
for(x=0;x<length;x++)
{
if(!isalnum(input[x]) && !ispunct(input[x]))
{
input[x] = ' ';
}
}
for(y=0;y<length;y++)
{
if(input[y]=='*')
{
input[y] = ' ';
}
}
printf("\nHere is you decrypted text: %c%c%c%c%c%c%c%c%c", input[0],input[3],input[6],
input[1],input[4],input[7],
input[2],input[5],input[8]);
/*
012
345
678
*/
}
else if(length == 16)
{
for(x=0;x<length;x++)
{
if(!isalnum(input[x]) && !ispunct(input[x]))
{
input[x] = ' ';
}
}
for(y=0;y<length;y++)
{
if(input[y]=='*')
{
input[y] = ' ';
}
}
printf("\nHere is your decrypted text: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", input[0],input[4],input[8],input[12],
input[1],input[5],input[9],input[13],
input[2],input[6],input[10],input[14],
input[3],input[7],input[11],input[15]);
/*
0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15
*/
}
}
puts("\n\n\n\n\n--------------------");
printf("\n\n Quit?");
puts("\n\n1 = no");
puts("2 = yes");
printf("\n\nEnter choice: ");
scanf("%d", &choice2);
switch(choice2)
{
case 1:
break;
case 2:
done = TRUE;
break;
default:
printf("Choose either 1 or 2!");
done = TRUE;
break;
}
}
return(0);
}
I realise that it is quite large. Are there any shortcuts that I have not taken?
|