help using strings and mapping
i need help understanding the logic and what i am supposed to do for my assignment. I have done part one and now part two is the following "
Quote:
The second part of the file contains the text to be encrypted. There is no limit on the number of lines, but no line will be over 80 characters long. Each alphabetic character (upper or lower case) will be replaced according to the cipher key selected based on the random number generation and the first 5 lines of the input file. Both the uppercase ‘A’ and the lower case ‘a’ are the first element of the alphabet and will both be replaced by the lower case letter that appeared first on the line selected for the cipher key (and now should be in the 0th element of the array). Any non-alphabetic character that appears on that line will just be maintained without any modification."
Here is the example: If the agreed upon Key is
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
i y k w v u t s a g p o c n l x r z h r b e d m f j
And the original message is
Hi, Jan
The encrypted message is
sa, gin
is what I am thinking on the right track. First check to see if the character in original message is a letter using isalpha then change to lower case using tolower and then mapp the characters which is where I am stuck. here is the code i have so far (as a function to be called in main)
Code:
void encrypt(char secret[],char message[], char coded[]){
int count, next;
char letter;
for(count = 0,count < MAXLEN,count++){ /* CHECK TO SEE IF LETTER */
letter = fgets(message,MAXLEN,stdin); /* GET LETTER FROM MESSAGE */
if(isalpha(letter)){ /* CHANGE TO LOWER CASE */
for(next = 0; message[next] != '\0';next++){
message[next] = tolower(message[next]);
}
}
}