0

I am having trouble with the code vigenere

This is for the key and using it instead of

for(int increase = 0; increase <= strlen(key); increase++)

k = strlen(s) % strlen(key) 


increase = 0; while ( increase < k) 

{ 
increase++ 
}

 Can I use this instead of the above?

(int increase = 0, k =strlen(s) % strlen(key); increase < k; increase++)
1

Sadly, no. In the walkthrough at around 4:30 Zamyla advises "advance to the next letter in keyword only when plaintext is a letter". It is conditional. Conditional suggests an if statement. There is no loop (ie no for or while).

This k = strlen(s) % strlen(key) looks like an attempt to handle the wraparound. Be warned, the index of key (assuming k here) is independent of the plaintext. It only depends on (the length of) the key. Every time you use a letter from the key, increase the index (k) by 1. But never let it be greater than the length of the key (that's where modulo comes in). Review the countoff example in the walkthrough at 6:05.

There are other details that will give you trouble; you are going to run into problems with the way you are handling case. Case of the plaintext and case of the key are independent of each other, great hint in walkthrough at 0:14. Think about how you could convert key[k] to a "caesar number" before you encipher the plaintext letter. Then you need only consider the case of the plaintext.

Suggest you rewatch the walkthrough, write the pseudocode as suggested, then attack the problem step-by-step. If you got caesar you can definitely get this.

5
  • How do i access the first char of key[k? I would think key[1] but it does not work.
    – Tom55555
    Jun 27 '17 at 7:37
  • Similar to the way you access the first char of the plaintext: key[0]. Jun 27 '17 at 11:08
  • int main (void) { printf ("please type a string\n"); string key = get_string(); printf ("please type a string\n"); string s = get_string(); if ( key > s ) { // didn't declare tried int didn't work key_length = strlen(s) % strlen(k); for (int increase = 0,; increase < key_length; increase++) printf("\nthis is key length: %c", key_length); } } I have some code no idea if it is correct. I have been testing many things and I still getting error am I close? argv1 I replaced by key.
    – Tom55555
    Jul 1 '17 at 4:57
  • This is not complete and I have no idea how to format the code. I did not take into consideration if the key is shorter but I can solve that if I solve this
    – Tom55555
    Jul 1 '17 at 5:00
  • ` int main (void) ` {` ` printf ("please type a string\n");` string key = get_string(); string s = get_string(); if ( key > s ) { // didn't declare tried int didn't work ` key_length = strlen(s) % strlen(k);` for (int increase = 0,; increase < key_length; increase++) ` {` printf("\nthis is key length: %c", key_length); } }
    – Tom55555
    Jul 1 '17 at 5:20

You must log in to answer this question.

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