#include <stdio.h>
#include <string.h> // strlen()
#include <ctype.h> // isupper() , tolower()
void vigenereCipher(char* plainText, char* key);
int main(int argc, char argv[])
{
char* key = argv[1];
char plainText[101];
// Ask the user for a sentence/word to encrypt
printf("Please enter a word or sentence: ");
fgets(plainText, sizeof(plainText), stdin);
// Print the used encryption key
printf("Your encryption key: %s\n", key);
// Print the encrypted plaintext
printf("Your encrypted message is: ");
vigenereCipher(plainText, key);
return 0;
}
void vigenereCipher(char* plainText, char* key)
{
int i;
char cipher;
char cipherValue;
int len = strlen(key);
// Loop through the length of the plainText string
for (i = 0; i < strlen(plainText); i++)
{
if (islower(plainText[i]))
{
cipherValue = ((int)plainText[i] - 97 + (int)tolower(key[i % len]) - 97) % 26 + 97;
cipher = (char)cipherValue;
}
else
{
cipherValue = ((int)plainText[i] - 65 + (int)toupper(key[i % len]) - 65) % 26 + 65;
cipher = (char)cipherValue;
}
// Print the ciphered character if it is alpha numeric
if (isalpha(plainText[i]))
{
printf("%c", cipher);
}
else
{
printf("%c", plainText[i]);
}
}
}
vigenere.c:7:5: error: second parameter of 'main' (argument array) must be of type 'char **' int main(int argc, char argv[]) ^ vigenere.c:10:15: error: incompatible integer to pointer conversion initializing 'char ' with an expression of type 'char'; take the address with & [-Werror,-Wint-conversion] char key = argv[1]; ^ ~~~~~~~ & 2 errors generated.
I'm aiming for the encryption
key of the program to be provided as an argument to the program but got the 2 errors above and don't know where to go from here. Any ideas? (end of code snippet)
This is for the CS50
project.