What is the reason one of my vigenere.c input files gives different results when checked with check50 and separately for the cases with BaZ and BAZ keys? My check50 results and my individual test cases with Baz and BAZ keys are given below

jharvard@appliance (~/Dropbox/pset2): check50 2014.fall.pset2.vigenere vigenere.c

:) vigenere.c exists
:) vigenere.c compiles
:) encrypts "a" as "a" using "a" as keyword
:) encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword
:( encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword
   \ expected output, but not "CaQGoh\n"
:) encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword
:( handles lack of argv[1]
   \ expected an exit code of 1, not a prompt for input
:( handles argc > 2
   \ expected an exit code of 1, not a prompt for input
:( rejects "Hax0r2" as keyword
   \ expected output, not a prompt for input
jharvard@appliance (~/Dropbox/pset2): ./vigenere BaZ
jharvard@appliance (~/Dropbox/pset2): ./vigenere BAZ

While trying to use Kareem's algorithm I tried to use a for loop to set all key values in the range (0-25 ). But I am getting an error message saying that the loop results are not being used. How can one reduce all key values to the range (0-25) without having another loop?


  • Your results are not different than what check50 outputs. In the first case with key BaZ and plaintext "BaRFoo", both you and check50 have as output "CaQGoh" which may be wrong but is consistent. On your second example you use as key BAZ which is correct, but your plaintext is wrong. You have "BAZFOO" while it should be "BARFOO". That's you have a different result. Your other sad faces are because when the user input's wrong input, or wrong number of inputs, you probably ask for new input, while you should exit the program returning 1. (continuing)
    – ChrisG
    Aug 4 '15 at 8:27
  • I don't really get what you mean in your final sentence though.
    – ChrisG
    Aug 4 '15 at 8:27
  • @Chris Cantidis. If I use return 1;command after printing "lack of argv[1]',then the program terminates immediately after the first line i.e ./vigenere bacon and prints the usual prompt without allowing me to type my plain text to be encrypted. That is why I did not use return 1 command in my program.uma1966
    – uma1966
    Aug 4 '15 at 22:33
  • That is exactly what the specification wants. To terminate the program, without asking for plaintext, if the user didn't input the correct number of arguments.
    – ChrisG
    Aug 5 '15 at 8:00

it appears that your program encrypts "BaRFoo" as "CaQGoh" using "BaZ" where the expected ciphered text is "CaQGon" (ends with an 'n').

it also appears that your program isn't handling the lack of argv[1] correctly. see How to handle the lack of argv[1] in caesar?!

and lastly your program doesn't ensure that the keyword contains alphabetical chars only.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .