Here's my question: Below in the beginning of my code, I am hoping to assign argv[1] as a string k. Then I want to subtract the value of 'A' or 'a' from each char, depending on its case. After all of this I hope to use this altered string to change the plaintext into encoded text.
Should I make a new string for this instead? I know that I shouldn't be using GetChar() but rather some other thing but I don't know what that would. I am trying to assign the new value of x to k[i].
Thanks for any help!
int main(int argc, string argv[])
{
int n = 0;
char x = 'a';
// checks if there is only one argument
if (argc == 2)
// declare array of chars that is the key
{
string k = argv[1];
n = strlen(k);
for (int i = 0; (i <= n + 1) ; i++)
{
if (isalpha(k[i]) || k[i] =='\0')
{
if (isupper(k[i]))
{
x = (k[i] - 'A');
//TODO: Change this so that k[i] is replaced with its new value of k[i] - 'A'
k[i] = GetChar();
}
if (islower(k[i]))
{
x = (k[i] - 'a');
k[i] = GetChar();
}
printf("Your key is %s\n", k);
//int key = (0 % strlen(k));
printf("Type your plaintext.\n");
string plain_text = GetString();
// check if alpha and then increase
for (int j = 0, n = strlen(plain_text); j < n; j++)
{
if(isalpha(plain_text[j]) && isupper(plain_text[j]))
{
printf("%c", ((plain_text[j] - 65 + k[j]) % 26) + 65);
}
if (isalpha(plain_text[j]) && islower(plain_text[j]))
{
printf("%c", ((plain_text[j] - 97 + k[j]) % 26) + 97);
}
else if (isalpha(plain_text[j]) == false )
{
printf("%c", plain_text[j]);
}
return 0;
}
}