/* This program prompts a user to input a string,
encrypts it using a randomly determined value,
displays the encrypted string, then unencrypts
and displays the original string as well as the
value that was used. */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int main()
{
unsigned i, k;
char array[80];
srand((unsigned)time(NULL));
k = rand()%110;
puts("Please enter a string to encrypt:");
gets(array);
for(i = 0; i < strlen(array); i++)
{
array[i] += k;
}
printf("Encrypted: %s\n", array);
puts("\nNow to decrypt the string.");
for(i = 0; i < strlen(array); i++)
{
array[i] -= k;
}
printf("Decrypted: %s\n", array);
printf("The key that was used was %d.\n", k);
system("PAUSE");
return 0;
}
:: Top ::