// This function does the actual encryption and decryption.
int Encrypt (char *string, char *Key, int mode)
{
// This algorithm stays within the keyboard character
// environment.
char *s = new char[1000];
int x;
int y;
int z;
int len_string;
int char_value;
if (mode == ENCRYPT)
{
len_string = strlen (string);
for (x = 0; x < len_string; x++)
{
if (string [x] == 0x9)
s [x] = 0x9;
else
{
z = (int) string [x] + ((int) Key [keycount] - 32);
if (z <= 126)
s [x] = (char) z;
else
{
z = z - 95;
s [x] = (char) (z);
}
keycount++;
if (keycount == key_length)
keycount = 0;
}
}
s [x] = NULL;
strcpy (string, s);
}
else if (mode == DECRYPT)
{
len_string = strlen (string);
for (x = 0; x < len_string; x++)
{
if (string [x] == 0x9)
s [x] = 0x9;
else
{
z = (int) string [x] - ((int) Key [keycount] - 32);
if (z >= 32)
s [x] = (char) z;
else
{
z = z + 95;
s [x] = (char) z;
}
keycount++;
if (keycount == key_length)
keycount = 0;
}
}
s [x] = NULL;
strcpy (string, s);
}
delete s;
return 0;
}