Welcome Guest [Log In] [Register]
Viewing Single Post From: Urrrgh! Help Plz
jdege
Member Avatar
Elite member
[ *  *  *  *  * ]
loki
Mar 7 2007, 03:56 PM
I removed static and inline, It was a mistake from an earlier project. Opps.
I prefer K&R bracing, I like it becuase its clean. Please do explain why thats not good.

I made a few adjustments and Its still not working. I find it very depressing, because to me the code is right. Clearly its not, otherwise I would giggling with self achievement.

I am really starting to think about making page on how to write a cipher for dummies by a dummy!

I appreciate the help, thanks.

I think I am going to have to printf every line until I see my error.

Included is what I have done.

Static has it's place. It's good style to keep scope as tight as possible.

Register and inline were never more than hints to the optimizer, and modern optimizers don't need these kind of hints. So register and inline are no more than clutter.

As for K&R bracing, some prefer it, others don't. I like being able to see a vertical match between an opening and closing brace - makes it easier for me to identify the scope of a compound statement. It's the oldest, and most pointless, flame war in the history of the C language.

But enough of the style quibbles:

Code:
 

   unsigned int last;
   unsigned int output;
   unsigned int current_byte;
   int mode;
   int i;

  case decrypt:
       i = 0;
       current_byte = fgetc(plain_text);
       printf("C[%d] = '%02X'\n", i, current_byte);
       output = baldr_decrypt(current_byte,*user_key);
       printf("D(C[%d]) = '%02X'\n", i, output);
       output = output ^ iv;
       printf("P[%d] = '%02X'\n", i, output);
       fputc(output, cipher_text);

       last = current_byte;
       i += 1;
       printf("\n");

       /* while we are still reading data */
       while ((current_byte = fgetc(plain_text)) != EOF)
       {
           /* has user key expired ? if so reset it*/
           if (*user_key == '\0')
               user_key = argv[1];

           printf("C[%d] = '%02X'\n", i, current_byte);
           output = baldr_decrypt(current_byte, *user_key);
           printf("D(C[%d]) = '%02X'\n", i, output);
           output = output ^ last;
           printf("P[%d] = '%02X'\n", i, output);

           last = current_byte;
           user_key++;
           /* write current byte */
           fputc(output, cipher_text);

           i += 1;
           printf("\n");
       }
       break;

When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.
Offline Profile Quote Post
Urrrgh! Help Plz · Off-topic