encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
# Checks
0 Running... clang -o vigenere vigenere.c -lcs50 -lm. ✔
1 Expecting an exit code of 0. ✔
2 Running... ./vigenere baz. ✔
3 Takes in standard input of world, say hello!. ✔
4 Expecting the following on standard out — xoqmd, rby gflkp!\n ... but received the following on standard out instead — xoqmd, szz gflkp!
My vigenere.c
fails on only this test case. The rest pass properly. I'm no sure if posting my source code here would violate the honor code, hence posting just the error instead.
I'm supposed to get rby
instead of szz
for the plaintext - say
, otherwise the rest of the ciphertext is also right as you can see.
Any ideas as to what I might be doing wrong?
UPDATE:
I'm trying to implement @superindesu's suggestions but the key that I am trying to use is generating funny.
I am using isalpha(char_variable)
and ispunct(char_variable)
but it's misreading a portion of the input and generating a wrong key. For debugging purposes, I've used -
to indicate output from ispunct()
and #
to indicate output from an else
block which catches anything other than alphabets or punctuations:
jharvard@appliance (~/Dropbox/pset2): ./vigenere-2 baz
world, say hello!
bazba-#zba#-#zba-# - key
Any ideas on how to fix this?
UPDATE 2: (Code)
string plaintext = GetString();
int keylen = strlen(key);
int ptlen = strlen(plaintext);
int j=0;
for(int i=keylen;i <= ptlen;i++){
if(isalpha(plaintext[i])){
key[i]=bigkey[j];
j++;
}
else if(ispunct(plaintext[i])){
key[i]='-';
}
else{
key[i]='#';
}
key[i+1]='\0';
}
printf("%s - key\n",key);
// bigkey is a string that has the key repeated to the length of the plaintext.
// key is the key provided at the command-line by the user
a
it's the same issue. I used-
and#
for clarity's sake here. Plus in the next segment I only take into consideration, places in thekey
variable that have corresponding alphabets in theplaintext
.