Updates

Victory! Sort of…

So I’m once again out of town. This time though I’m pulling a two week stint and I’m enjoying my paid day of rest. I’ve spent the whole day working on my Caesar Cypher and my Vigenere (Vig) Cypher. I’ve prettied up my Caesar Cypher by removing the heavy lifting to two functions. Also, the actual function I used to encrypt the message I can actually use in both cyphers. Stack Overflow has become an excellent resource. It seems like there are people out there with nothing better to do than answer other peoples questions.

I’ve uploaded the updated versions of my Caesar Cypher as well as my Vig Cypher. Heres the link:
https://www.dropbox.com/sh/03al9iunbl4z6an/wf04LqhASw

Here lies the rub: my Vig Cypher to compile. I tried to just post it here direction as a code block BUT for some reason WordPress decided to completely ignore entire chunks of my code, completely erasing them. Soooo, if you want to help me find my problem you’ll have to download it from my Dropbox. Cest la vie…

Anyway, I keep getting an error at line 32 where I have:

CypherShift (plainText[i], argv [1][j]);

The error I get is: passing argument 2 of ‘CypherShift’ make pointer from integer without a cast

I also get this error on like 9 where I prototype the function: note: expected ‘const char*’ but argument is of type ‘char’

So yeah, I dont want to vomit my entire wee program onto Stack Overflow and thus beg for help. I think its a bit out of good form to do that. So if the world reading this has any input, I’d appreciate it.

Advertisements
Standard

3 thoughts on “Victory! Sort of…

  1. The joy of pointers… the error in line 9 is more clear, and describes better what is going on. When you pass ‘argv[1][j]’, you are actually passing the character value. So if your cipher string is ‘cat’, you are passing in ‘c’ (on the first iteration).

    Your function signature says to expect a char pointer. That means instead of passing in the ‘c’, you want to pass in the address that is storing the character ‘c’.

    So there are two ways of solving the problem, either of which are correct. You can pass in the character, and change your function (and signature) to expect a character instead of a char pointer, or you can pass in the char pointer and leave your function as it is.

    Sometimes you will find that compiler errors are pretty obscure. When it is, focus on the errors you can understand and fix them first. Sometimes that will get rid of the error messages that don’t seem to make sense.

    • So I went and changed the function and its prototype to expect a char and that fixed things up nicely. However in fixing one bug I found another.

      It doesnt break the program, it just doesnt do what I intended.

      So if my key word is “cat” and my plaintext is “dog” it will iterate over each char in “dog” with each char in “cat”. So I end up getting a cypher text that is the length of the key word multiplied by the length of the cyhper text. I found the problem but I dont know how to fix it.

      When I call the function in main, it basically does this:
      For (length of plaintext)
      for (length of key word)
      shift char
      iterate cypher char
      shift plaintext char

      So yeah, I cant figure out a good way to exit the second loop after encodes things only once.

      Good times.

      • It’s not doing what you want because nested for-loops iterate the entire inner collection over every item of the outer collection. For example:
        for (int i = 0; i < 3; i++)
        {
        for (int j = 10; j < 12; j++)
        {
        DoSomething(i, j)
        }
        }
        will call DoSomething with the following:
        i = 0, j = 10
        i = 0, j = 11
        i = 1, j = 10
        i = 1, j = 11
        i = 2, j = 10
        i = 2, j = 11

        What I would probably do instead is this:
        for (int i = 0; i < strlen(plaintext); i++)
        {
        int keyIndex = i % strlen(keytext)
        DoSomething(plaintext[i], keytext[keyIndex])
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s