473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how can i store huge values?

I am trying to make a cipher with a 256-bit key but i have no idea how
the store this key without using arrays of ints or something like that.
I just need a type that is big enough to hold the entire key, because i
am going to use multiplication operations and such, which i can
impossibly use on arrays or so i think. Is there a way to treat an
array as a single, huge number without really being that? Any help is
appreciated!

Nov 15 '05 #1
4 1811
In article <11*********************@o13g2000cwo.googlegroups. com>,
RubenDV <ru***************@skynet.be> wrote:
I am trying to make a cipher with a 256-bit key but i have no idea how
the store this key without using arrays of ints or something like that.
I just need a type that is big enough to hold the entire key, because i
am going to use multiplication operations and such, which i can
impossibly use on arrays or so i think. Is there a way to treat an
array as a single, huge number without really being that?
Not within standard C.
Any help is appreciated!


You should get one of the portable "bignum" packages that provide
arithmetic operations on arbitrary precision integers.

--
"Never install telephone wiring during a lightning storm." -- Linksys
Nov 15 '05 #2
RubenDV wrote:
I am trying to make a cipher with a 256-bit key but i have no idea how
the store this key without using arrays of ints or something like that.
I just need a type that is big enough to hold the entire key, because i
am going to use multiplication operations and such, which i can
impossibly use on arrays or so i think. Is there a way to treat an
array as a single, huge number without really being that? Any help is
appreciated!


General (not C specific) algorithm questions often get better answers
in comp.programming, so you might want to post such there rather than
here. I suggest you google for "bignum library", sounds like that
is what you want.

-David

Nov 15 '05 #3
>I am trying to make a cipher with a 256-bit key but i have no idea how
the store this key without using arrays of ints or something like that.
I just need a type that is big enough to hold the entire key, because i
am going to use multiplication operations and such, which i can
impossibly use on arrays or so i think. Is there a way to treat an
array as a single, huge number without really being that? Any help is
appreciated!


One way to do it is to store the key as an ASCII decimal number in
a 257-byte character array (including '\0' terminator. You can do
the multiplication like you learned to in elementary school, handling
a digit at a time. I didn't say it would be efficient. One advantage
is that the result is already formatted so you can print it.

You can also look at 'bignum' packages, which tend to represent
things as arrays of (unsigned) integers, but the work is done for
you. Many of them work a lot like the decimal number approach,
except they are using base-65536 or base-2**32 or some other large
number of bits which is more efficient.

Gordon L. Burditt
Nov 15 '05 #4
"RubenDV" <ru***************@skynet.be> wrote:
I am trying to make a cipher with a 256-bit key but i have no idea how
the store this key without using arrays of ints or something like that.
I just need a type that is big enough to hold the entire key, because i
am going to use multiplication operations and such, which i can
impossibly use on arrays or so i think. Is there a way to treat an
array as a single, huge number without really being that?


Yes; primary school mathematics extended to larger bases; in this case,
you're probably doing base-2**32 math instead of base-10. All you need
is an array of 8 uint32_t's (or another typedef for an unsigned integer
you know is 32 bits large (or another known, fixed, size)), and an
understanding of long multiplication.

In primary school, when you were taught to multiply two numbers, say 123
and 234, how did you do that? Like this:

234
345
---*
1170
936
702
-----
80730

Now, instead of digits from 0 to 9, you're multiplying integers from 0
to (2**N)-1, but the principle remains the same. You don't even need the
sub-results; all you need are two source integers, if you wish two
working integers (though at a pinch you can do without), and the result
array.

Richard
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steve | last post by:
Hi, I have a web application where there are a number of columns a user can sort on (price, item etc). The database itself is HUGE (around 6 million rows) and even with all the indexing it slows...
2
by: NWx | last post by:
Hi, Is Cache appropriate to store persistent variables used across the application? What I want is to store UserID for currently logged user, SessionID (my own SessionID, which keep track of...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: serge calderara | last post by:
Dear all, One simple question relative to store procedure withinh ASP code on a web page. Let say that I am calling a store procedure to execute from a server button click on my web page. That...
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
4
by: Dave G | last post by:
Firstly, apologies as this is not strictly an Access problem. I have a Access 2003 database containing records about people, and each person has 2 photos associated with the record. The photos...
9
by: Ajinkya | last post by:
Hello friends ! , I am very new to java script.If anyone can help me then I will be very very thankful to his/her. I am using php and mysql in my project and I have one textarea and one...
3
by: Ahmad Jalil Qarshi | last post by:
Hi, I have a text file having size about 2 GB. The text file format is like: Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values For example...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.