pylua
pylua

Reputation: 635

Take modulus of a byte String

I have a 128 bit number stored like this...

unsigned char upperHalf [8];
unsigned char lowerHalf [8];

Where the upperHalf is the upper 8 bytes of the number (In Big Endian Format) And the lower half is the lower 8 bytes of the number (In Big Endian format)

The big restriction is that I can not use an unsigned long long to fit the 128 bits...

sizeof(unsigned long long ) returns 8. 

I need to modulo this 128 bit number with a 64 bit number.

I was wondering if was there an efficient way to do this?

Upvotes: 2

Views: 959

Answers (1)

Zac Howland
Zac Howland

Reputation: 15872

Yes and no.

You would need to write your own function to do the modulus properly (unless you can assume it will always be a power of 2, which would allow you to just do shifts). Or you can use a Big Integer library (e.g. https://mattmccutchen.net/bigint/).

Upvotes: 1

Related Questions