I'm currently working on pset2. I have the following problem however, which I cant seem to debug:
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword \ expected output, but not "CaRGon\n" :( encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword \ expected output, but not "CARGOO\n"
All other tests are passed by the cs50 check. This is the part of my code that carries out the encryption.
#define ALPHABET 26
/*char *in: Text to be encrypted.
char *k: Keyword used for Vigenere encryption.
int sz1: Length of input string.
int sz2: Length of keyword. */
void VigCipher (char *in, char *k, int sz1, int sz2){
int a = 0, b = 0, c = 0;
for (a = 0; a < sz2; a++){
if ( islower(k[a]) ){ //Set to 0-25
k[a] -= 97;
}
else if ( isupper(k[a]) ){ //Set to 0-25, such that uppercase and
k[a] -= 65; //are equivalent.
}
}
int wrap = 0;
for (b = 0; b < sz1; b++){ // Up to string length of plaintext.
if ( isalpha(in[b]) ){
if (c == sz2) { //If c reaches strlen of key, bring back to 0.
c = 0;
}
if (islower(in[b])) { // If dealing with lowercase
if ( islower( in[b] + k[c]) ) { //Ensure it remains lowercase
in[b] += k[c]; //Carry out
}
else { // If not, wrap around.
wrap = ALPHABET - k[c];
in[b] -= wrap;
}
}
else if ( isupper( in[b] + k[c]) ) {
if ( isupper( in[b] + k[c]) ) {
in[b] += k[c];
}
else {
wrap = ALPHABET - k[c];
in[b] -= wrap;
}
}
c++;
}
}
}