I am working to take c code from an academic paper and edit. I am studying cryptographic algorithms. I have ran the following code, but I am having a little difficulty understanding two things. First, the program uses unsigned long ints. When they are added or subtracted, I don't get the values I would expect. For example:

P, Q, My sum by hand, sum using c
01100011010100011110000110110111
10111001011110010011011110011110
00011100110010110001100101010101
00011100110010110001100001010110

I understand that unsigned long int is 32 bit and that the addition is mod 2^32, but I thought the last carry bit when you add to the left by hand would be lost. Is it somehow added back on the right side?

Second, when I run the code, the output should include 5 examples in hex, but when I run it, the results have a lot of 0's mixed into the results. If you remove the 0's, the results are correct. Is this something I have done?

Thanks,
Chris

Recommended Answers

All 4 Replies

Your printword() function is making the results look different from the paper. Try this instead:

void printword(WORD A) {
    printf("%08X ", A);
}

That did the trick! Thanks!

Any ideas regarding the addition (and subtraction)?

I didn't understand that question. Could you elaborate and possibly provide a simple example outside of the encryption algorithm of what you're confused about?

Sorry. In trying to reproduce this, I realized it was my own math mistake.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.