Manipulating with large numbers in C

H

Halid Umar A M

Hi All,
I m Halid Umar, network security research student. I will explain
my situation and give me hint if you can. I expect reply from you all.

* I have to handle numbers that have more than 64 bit like 128bit in
cryptography applications.

* For example, if i want to add two 128 bit numbers what should i do in
C.

* Please explain me with example please.

Hope reading you soon.

Regards,
Halid Umar A.M
 
R

Richard Heathfield

Halid Umar A M said:
Hi All,
I m Halid Umar, network security research student. I will explain
my situation and give me hint if you can. I expect reply from you all.

For your information, "I expect reply from you all" makes it sound like you
are the boss, we are your servants, and we have to do what you say. I know
you don't mean to sound like that. I suggest you avoid the words "expect
reply".

I recommend, also, that you do a little research into the word "please".
* I have to handle numbers that have more than 64 bit like 128bit in
cryptography applications.

* For example, if i want to add two 128 bit numbers what should i do in
C.

Either use an existing bignum library:

http://www.gnu.org/software/gmp/ (GMP)
http://indigo.ie/~mscott/ (Miracl)

or write your own.
* Please explain me with example please.

Ah! You see? You do know the word. :)
 
H

Halid Umar A M

Hello Mr.Richard,
I am really sorry for the sentence i have framed for the question.
As I am not a native speaker of English, I framed wrong sentence
without respect. Really I didnt mean in that way. Please apologise me
for my bad english. I am also improving my english.

Thanks for your quick response and again i am sorry for that.

Halid Umar
 
R

Richard Heathfield

Halid Umar A M said:
Hello Mr.Richard,
I am really sorry for the sentence i have framed for the question.

No need to apologise. I was not offended. I was just trying to help you to
avoid giving offence to some of the more sensitive souls in here.

Anyway, like I said, you want either GMP, Miracl, or plenty of time and
coffee. :)
 
H

Halid Umar A M

Hello Mr.Richard,
Thanks, I tried to send you a personal mail but i could not find
your personal id. Please if you dont mind, send me a mail to my id so
that i can communicate with you easily without spamming to all.
(e-mail address removed) or (e-mail address removed) ; thanks again.

Regards
Halid Umar
 
J

jacob navia

Halid Umar A M a écrit :
Hi All,
I m Halid Umar, network security research student. I will explain
my situation and give me hint if you can. I expect reply from you all.

* I have to handle numbers that have more than 64 bit like 128bit in
cryptography applications.

* For example, if i want to add two 128 bit numbers what should i do in
C.

* Please explain me with example please.

Hope reading you soon.

Regards,
Halid Umar A.M
If you use the lcc-win32 C compiler you do:

#include <stdio.h>
#include <int128.h>
int main(void)
{
char buf[512];
int128 a = 1,b;

b = (a << 94);
i128toa(&b,buf);
printf("%s\n",buf);
}

Output
19807040628566084398385987584

Support for 128 bit integers is quite new, and I haven't gotten around
to add the printf/scanf support. But most functions are working now.

To get lcc-win32 go to:

http://www.cs.virginia.edu/~lcc-win32

P.S. Note that this are EVIL EXTENSIONS that will make you think that
lcc-win32 is a good compiler and other compilers just do not cut it :)
 
A

Andrew Poelstra

Halid said:
Hello Mr.Richard,
Thanks, I tried to send you a personal mail but i could not find
your personal id. Please if you dont mind, send me a mail to my id so
that i can communicate with you easily without spamming to all.
(e-mail address removed) or (e-mail address removed) ; thanks again.

Regards
Halid Umar

The other members of the group want to hear what you have to say. They
just... enjoy whining about everything that goes against the tradition
of the group.

Anyway, please quote what was said before; click 'More Options' and 'Add
Reply' instead of using the broken Reply link at the bottom.

If you are making your own 128-bit numbering system, what base do you
want to use? (10 would be most natural, but 16 would be much easier).
 
A

August Karlstrom

R

Richard Heathfield

jacob navia said:
If you use the lcc-win32 C compiler

Is there not an lcc-win32 newsgroup?

The reason for this newsgroup's focus on portability has been explained to
you time and time again. You are damaging your reputation, and by extension
the reputation of your product, by continuing to ignore that focus. Does
that not concern you?
 
C

CBFalconer

jacob said:
.... snip ...

Support for 128 bit integers is quite new, and I haven't gotten around
to add the printf/scanf support. But most functions are working now.

To get lcc-win32 go to:

http://www.cs.virginia.edu/~lcc-win32

P.S. Note that this are EVIL EXTENSIONS that will make you think that
lcc-win32 is a good compiler and other compilers just do not cut it :)

There is no need for any EVIL EXTENSION. You can define a long
long as a 128 bit quantity, a long as 64 bits, an int as 32 bits, a
short as 16 bits, and a byte (or char) as 8 bits and remain
perfectly standard. No need for non-standard headers such as
<int128.h>.

You seem determined to promulgate the Microsoft disease of
flagrantly ignoring standards and attempting to lock in the
uneducated to your peculiar system and bugs.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
J

jacob navia

Richard Heathfield a écrit :
jacob navia said:




Is there not an lcc-win32 newsgroup?

The reason for this newsgroup's focus on portability has been explained to
you time and time again. You are damaging your reputation, and by extension
the reputation of your product, by continuing to ignore that focus. Does
that not concern you?

I fail to see why supporting 128 bit integers "damages my reputation".
lcc-win32 has a lot of numeric types, and gives the user the possibility
of writing his/her own numeric types. You may disagree with how it is
done, or whether at all should be done. You are entitled to your opinion.

The "focus of this group" is nowhere stated, this group has no chart and
usenet is free. Yes, there is a group of people that think that all
improvements that compilers do to the language or to the run time
are to be banned and reduce C to a dead language, ready to be taken over
by C++.

Even such a simple thing like 128 bit integers provokes endless polemic,
without any substantive arguments of your part. Why should 128 bit
integers be banned? You do not say, and stay (as always) discussing
about what is on topic or not, never about whether something is correct
or incorrect or whether there is any advantage/disadvantage for using it.

Why are 128 bit integers OFF TOPIC here?

Because you say so?

Portability is one of the many factors that rule software construction,
as you may know. Usage is another. Try to write a 128 bit library and
you will se that is much more easy to use lcc-win32's library.

And please keep in mind that portability at all costs is nonsense.

jacob
 
R

Richard Heathfield

jacob navia said:
Richard Heathfield a écrit :

I fail to see why supporting 128 bit integers "damages my reputation".

It doesn't, and I didn't claim it did. But now your reputation for being
able to read is in danger.
 
J

jacob navia

Walter Roberson a écrit :
They aren't, but #include <int128.h> is, as is the int128 type.

I asked in comp.std.c how I should name those, and all answers I got
pointed to such a name. The alternative "long long long" was completely
idiotic :)

True, you have to include the 128 bit header since it is not enabled by
default... so what?

How else should I have done it?

And I fail to see what is so wrong with
#include <int128.h>

It is 100% standard C. True, the contents of that file are not in the
standard but what is wrong with that?
 
J

jacob navia

CBFalconer a écrit :
jacob navia wrote:

... snip ...



There is no need for any EVIL EXTENSION. You can define a long
long as a 128 bit quantity, a long as 64 bits, an int as 32 bits, a
short as 16 bits, and a byte (or char) as 8 bits and remain
perfectly standard. No need for non-standard headers such as
<int128.h>.

I wanted to do that for the 64 bit port (lcc-win64). I would have done
it if it weren't because both gcc and MSVC treat long long as 64 bits.
I would have been the only compiler to do that, and all code from both
gcc and MSVC would have been forced to be PORTED to my compiler system,
it would never compile without some tweaking.

Of course code that assumes that long long is 64 bits is (in principle)
wrong, but there is alreay SO MUCH CODE that assumes that, that it
wouldn't have been wise to follow that path.
> You seem determined to promulgate the Microsoft disease of
> flagrantly ignoring standards and attempting to lock in the
> uneducated to your peculiar system and bugs.

This is nonsense. I do not ignore standards. I implemented a
non-standard data type. Please keep in mind that extensions are NOT
FORBIDDEN by the standard. They should NOT introduce new keywords,
that's all. That is why there is an include of a header file. There is
NO new "int128" keyword.

I have repeated this AD NAUSEUM. Over and over. And always there are
people that tell the uneducated masses that extensions are "forbidden".

Please read the standard before you start labelling systems as
"non-standard".
 
B

Ben Pfaff

jacob navia said:
I asked in comp.std.c how I should name those, and all answers I got
pointed to such a name. The alternative "long long long" was completely
idiotic :)

True, you have to include the 128 bit header since it is not enabled by
default... so what?

How else should I have done it?

Name your 128-bit type "int128_t" and make it available upon
including <stdint.h>.
 
A

Al Balmer

Richard Heathfield a écrit :

I fail to see why supporting 128 bit integers "damages my reputation".

You (deliberately?) misunderstand. It's your insistence on talking
about it here that damages your reputation.
lcc-win32 has a lot of

features which are off-topic here.

The "focus of this group" is nowhere stated,

You know better. The focus of this group has been stated clearly many
times, and a large proportion of those times, it was stated directly
to you.
<snip>
 
J

jacob navia

Ben Pfaff a écrit :
Name your 128-bit type "int128_t" and make it available upon
including <stdint.h>.

Well, I think you are 99% right actually.

The only problem is that it would be enabled by default...

But in any case intXXX_t is a reserved word isn't it?

The rationale for making it optional is avoiding clobbering some other
int128 type that may exist in user name space. But int128_t is probably
reserved.

jacob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top