#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, string argv[])
{
if(argc != 2) // RETURNS TO 1 if not 2 strings
{
printf("Usage: ./caesar k\n");
return 1;
}
// calculate length of string and make sure it is alpha
string keyphrase = argv[1];
// Get string length and calculate characters and loop string
for (int j = 0, l = strlen(keyphrase); j < l; j++)
{
if(!isalpha(keyphrase[j]))
{
printf("Please ensure all characters are alphabetical.\n");
return 1;
}
else if(isalpha(keyphrase[j]))
{
printf("plaintext: ");
string s = get_string();
printf("ciphertext: ");
// CUT OFF HERE JUST IN CASE and also cipher plain text from here on out
for(int i = 0, n = strlen(s); i < n; i++)
{
if(isalpha(s[i]) && isupper(s[i]))
{
// convert asci to alphbetical for upper case
int cipher = s[i]-65;
int c = (cipher + keyphrase[j % l]- 65) % 26;
printf("%c", c+65);
}
//convert for lower case
else if(islower (s[i]) && isalpha(s[i]))
{
int cipher2 = s[i]-97;
int d = (cipher2 + keyphrase[j % l] - 97) % 26;
printf("%c", d+97);
}
//PRESERVE DIGITS SPACES AND PUNCTS NEW HEERE
else if(isdigit (s[i]))
{
printf("%c", s[i]);
}
else if(ispunct (s[i]))
{
printf("%c", s[i]);
}
else if(isspace (s[i]))
{
printf("%c", s[i]);
}
// PASTED CODE ENDS HERE JUST IN CASE
}
//print space after i for loop
printf("\n");
return 0;
}
}
}
THis is how far I got so far in vigenere and I am stuck I really dont know how to fix my keyword and I just dont understand :(