🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

huge integers

Started by
0 comments, last by NewDeal 24 years, 4 months ago
Im working on a cryptography app using the RSA algorithm. Anyways, my problem is that i need to work with integers as big as 1024 bit (well 512 would do, but same problem). How would u guys implement this. The only solution i can come up with at the moment is to use an array of binaries and the write the operator functions myself. Im pretty sure that this would be a pretty slow solution and since speed is important id really like to find another way to do this. PS. Its a school asignment and only 64 bit keys r required. Id like to get a good grade tho, so any help will be very appreciated. Thanx
Advertisement
Well, I once spent an entire History class period (1 hour) thinking about this last year, and I figured out that the easiest way would be this:

Use two 32 bit integers, if your machine doesnt support 64 bit.

its easiest if everything is unsigned.

when you add two of them, just add the two lower ints, and then check the CPU''s overflow flag. Im not sure exactly, maybe someone else knows, but I think its standard on most processors.

then add the higher ints.

if the lower ints overflowed, then add 1 to the higher int.

same way with subtraction.

multiplication may be a bit icky =(
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.

This topic is closed to new replies.

Advertisement