When my cipher algo sees an "a" it seems to wipe out the rest of the keyword, returning only a " ", which seems to erase the rest of my keyword, leaving my encryption useless. I've debugged this several times and it works with other letters
Full code below:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
// getting stuck passing letters into integers to create one cypher
int main(int argc, char *argv[]){
if (argc == 2){
char *key_word = argv[1];
int length = strlen(key_word);
//convert to ciper values and store as a converted key
for (int k = 0; k < length; k++){
if (islower(key_word[k])) {
int num = (key_word[k] - 97)%26;
key_word[k] = num;
}
else {
int num = (key_word[k] - 65)%26;
key_word[k] = num;
}
}
//get plain text from user
printf("plaintext:");
char *plain_text = get_string();
int j = 0;
//start looping through each letter
for (int i = 0; i < strlen(plain_text); i++){
//check length of j counter for cipher key and reset if to large, otherwise use j
if (j < strlen(key_word)){
if (isupper(plain_text[i])){
plain_text[i] = (((plain_text[i] -65)+key_word[j])%26+65);
}
else {
plain_text[i] = (((plain_text[i] -97)+key_word[j])%26+97);
}
j++;
}
else {
j = 0;
}
}
printf("ciphertext: %s\n", plain_text);
}
else {
printf("error");
return(1);
}
}