This is driving me mad. I think I have implemented Caesar correctly, but Vigenere does not seem to work. I've tried everything. Please, let me know what happens. PD Sometimes, the terminal, halfway through ciphering, prints 'Floating point exception (core dumped)'. I don't know why this happens.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main (int argc, string argv[])
{
string keyword = argv[1];
int key;
char ciphered;
int h;
int j;
int plain;
if (argc < 2)
return 1;
for (int o=0; o<strlen(keyword); o++)
{
if (!isalpha(keyword[o]))
return 1;
}
string plaintext=GetString();
h=strlen(keyword);
for(int i=0; i<strlen(plaintext); i++)
{
j = ((strlen(keyword))%h);
key=0;
if (isupper(keyword[j]))
key=(keyword[j]-65);
if (islower(keyword[j]))
key=(keyword[j]-97);
plain=plaintext[i];
ciphered=((plain+key)%26);
if (isupper(plaintext[i]))
ciphered+=65;
if (islower(plaintext[i]))
ciphered+=97;
printf("%c\n", ciphered);
ciphered=0;
if (isalpha(plaintext[i+1]))
h--;
}
return 0;
}