Main Page | Report this Page
 
   
Science Forum Index  »  Cryptography Forum  »  Long division algorithm
Page 2 of 5    Goto page Previous  1, 2, 3, 4, 5  Next
Author Message
Tim Smith
Posted: Thu Dec 25, 2003 12:48 pm
Guest
In article <1d54b7e4.0312241731.1b6bc46b@posting.google.com>, mike3 wrote:
Quote:
Could you please post a description of how to do long division of very
large numbers on a computer? I need one for the crypto program I'm making.

First be sure you actually need long division. For many (most?) crypto
applications, you actually need mod, not div. One way to implement mod is
to divide and take the remainder, but there may be better ways.

In particular, often you only need mod, and only immediately after
multiplication, and then you can sometimes build the mod into the multiply.

For example, I needed a very simple RSA encryption with low exponent (3),
just once per session (basically to get a session key to a server), and
speed wasn't too much of a concern. Because this only involves three
mul/mod operations, there was no need for fancy algorithms, so this
ridiculously simple algorithm works (psuedocode):

// compute A*B mod N. Assumes A, B in [0,N)
bignum mod_mul( bignum A, bignum B, bignum N )
{
bignum R = 0;
while ( A != 0 )
{
if ( A & 1 )
{
R = R + B;
if ( R >= N )
R = R - N;
}
A = A / 2;
B = B * 2;
if ( B >= N )
B = B - N;
}
return R;
}

--
--Tim Smith
Tom St Denis
Posted: Thu Dec 25, 2003 1:03 pm
Guest
"Tim Smith" <reply_in_group@mouse-potato.com> wrote in message
news:ppFGb.19538$Pg1.9440@newsread1.news.pas.earthlink.net...
Quote:
In article <1d54b7e4.0312241731.1b6bc46b@posting.google.com>, mike3 wrote:
For example, I needed a very simple RSA encryption with low exponent (3),
just once per session (basically to get a session key to a server), and
speed wasn't too much of a concern. Because this only involves three
mul/mod operations, there was no need for fancy algorithms, so this
ridiculously simple algorithm works (psuedocode):

// compute A*B mod N. Assumes A, B in [0,N)
bignum mod_mul( bignum A, bignum B, bignum N )
{
bignum R = 0;
while ( A != 0 )
{
if ( A & 1 )
{
R = R + B;
if ( R >= N )
R = R - N;
}
A = A / 2;
B = B * 2;
if ( B >= N )
B = B - N;
}
return R;
}

Yes that works but it's ridiculously slow and not a good source to learn how
todo bignum math properly.

Tom
Roger Wilco
Posted: Thu Dec 25, 2003 1:39 pm
Guest
"Tom St Denis" <tomstdenis@iahu.ca> wrote in message news:<NODGb.83576$2We1.32267@news04.bloor.is.net.cable.rogers.com>...
Quote:
"Mok-Kong Shen" <mok-kong.shen@t-online.de> wrote in message
news:3FEAFD3D.96A8409@t-online.de...


Tom St Denis wrote:

"Mok-Kong Shen" <mok-kong.shen@t-online.de> wrote:

Spend some quarter of an hour and lots of your countrymen
(and even you yourself) might get benefits from that.

You don't think I spend time on my LT projects? I'm doing my bit in my
own
way.

It's a matter of 'global' optimization. If you are not
spending every minute available on that project (which
you seemingly aren't), then eventually having a better
public library system is likely worth much more personally
than what occassionally comes out from a usenet discussion
in my humble view.

I don't spend every waking minute working on LT projects because I'm still
in school. I have to also work to pay bills and of course i need time to
relax [re: play games].

The fact that I was working on my OMAC code on christmas day kinda shows I
got a bit of dedication to the project [cuz it's fun].

Tom


Data encryption 360 degrees rotation document 90 degrees and
encryption
on every angel then change it two binary code and fold it over like a
piece of paper then having the one's and zero cancel each other out.

if you written a very long letter and then change it two binary code
it would look like this

01010101010101010101010
10010101010101010101010
01010101001010101010010
00010101000101010101010
10010101010100101010101
would equal = 01
01010101010100001100101
01001010101010101010111
11110111001101010101010
01010101010101010101010
10101010101010101010101

if you took the piece of paper and folded it and folded it and folded
it the 0 and 1 would cancel each out and if you keep folding the piece
of paper too the smallest you would have 4 numbers left if 1+1 =
nothing and 0 + 0 = nothing 1+0=1 and 0+1+0
01 now if the key new the folding times you could send 2 bytes over
the internet and unzip a
100 zetabyte program you computer could store all the programs ever
written but just need the key to unzip then you could us this for SETI
for signals or can you imagine a computer processor that would be 1.8
Hz but run like 100 million zeta hz you could use the new 64 bit
process second side to unzip while the front side processes. or use
this for the matrix or quantum computing or supercomputer. 64 bit. 1+1
= nothing and 0 + 0 = nothing 1+0=1 and 0+1+0 dont forrget to use <
and > signes 0>1+1<0
Marcel Martin
Posted: Thu Dec 25, 2003 5:01 pm
Guest
Tim Smith a écrit :
Quote:

In article <1d54b7e4.0312241731.1b6bc46b@posting.google.com>, mike3 wrote:
Could you please post a description of how to do long division of very
large numbers on a computer? I need one for the crypto program I'm making.

First be sure you actually need long division. For many (most?) crypto
applications, you actually need mod, not div. One way to implement mod is
to divide and take the remainder, but there may be better ways.

In particular, often you only need mod, and only immediately after
multiplication, and then you can sometimes build the mod into the multiply.

For example, I needed a very simple RSA encryption with low exponent (3),
just once per session (basically to get a session key to a server), and
speed wasn't too much of a concern. Because this only involves three
mul/mod operations, there was no need for fancy algorithms, so this
ridiculously simple algorithm works (psuedocode):

// compute A*B mod N. Assumes A, B in [0,N)
bignum mod_mul( bignum A, bignum B, bignum N )
{
bignum R = 0;
while ( A != 0 )
{
if ( A & 1 )
{
R = R + B;
if ( R >= N )
R = R - N;
}
A = A / 2;
B = B * 2;
if ( B >= N )
B = B - N;
}
return R;
}

--
--Tim Smith

Good idea. Not only this is a good source to learn [*] but it might
be very useful to debug more complicated routines (since it allows
to compare results).

[*] If I remember well, in the cursus I followed, the study of
multi-precision divisions started with binary divisions.

mm
--
http://www.ellipsa.net/
mm@ellipsa.no.sp.am.net ( suppress no.sp.am. )
Tom St Denis
Posted: Thu Dec 25, 2003 5:15 pm
Guest
"Marcel Martin" <mm@ellipsa.no.sp.am.net> wrote in message
news:3FEB5E49.A68FD78F@ellipsa.no.sp.am.net...
Quote:
Good idea. Not only this is a good source to learn [*] but it might
be very useful to debug more complicated routines (since it allows
to compare results).

Um a standard I've seen for mulmod is to write a multiplication routine,
write a division routine and then write a routine which calls them both.
It's inefficient I guess but simpler IMO.

Specially since a normal baseline multiplier is trivial to understand
[complete pseudo-code in under one page, see pp89 of my text].

Quote:
[*] If I remember well, in the cursus I followed, the study of
multi-precision divisions started with binary divisions.

Seeing how I explained the abstract of MP division on one B5-sized [smaller
than A4, pp206] page [and the entire pseudo-code handling all cases in two
pages, pp209-210] in my textbook I can't really see the validity in your
argument. Saying "it's too complicated" then just not looking at the
references makes you an ignorant ignorant person.

Of course if I said the sky was blue and water was wet you'd argue that too
I guess..

To[com
Tim Smith
Posted: Thu Dec 25, 2003 5:40 pm
Guest
In article <RDFGb.84726$2We1.48091@news04.bloor.is.net.cable.rogers.com>,
Tom St Denis wrote:
Quote:
Yes that works but it's ridiculously slow and not a good source to learn
how todo bignum math properly.

Yeah, but if all you are doing is RSA encryption with exponent 3, once at
the start of a session to send a session key for use with, say, AES, it is
fast enough for many applications.

If you need to generate keys, or do RSA decryption, it will blow donkey
lincolns, of course.

I've got someone who insists on talking to my server from Perl programs on
Windows, and for some reason, can't get the Perl bignum library to work on
the ActiveState Perl port. The simple shift and reduce mul/mod in Perl,
representing bignums as arrays of base 256 digits, is taking about half a
second to do an encryption with a 1024 bit modulus, so I've went with that,
rather than something "better".

I did have some fun one afternoon playing around with speeding the simple
shift and reduce method up, by working a byte at a time instead of a bit at
a time, using a table lookup to figure out what to subtract at the reduce
stage, and that doubled the speed or so, and could have been better had I
not been real lazy and did a linear search on a sorted table of 256 items at
one point (yes, I am ashamed).

Getting extreme, I think with about 16 megabytes of tables, this could be
made a lot faster, possibly fast enough to rival the "good" methods for
small enough modulus, and 1024 bit might be small enough. Have to come back
and explore that path again someday...memory is getting cheap.

--
--Tim Smith
Douglas A. Gwyn
Posted: Fri Dec 26, 2003 12:42 am
Guest
"Tom St Denis" <tomstdenis@iahu.ca> wrote ...
Quote:
"Douglas A. Gwyn" <DAGwyn@null.net> wrote in message
news:bsf33d$8vs$1@ngspool-d02.news.aol.com...
"Tom St Denis" <tomstdenis@iahu.ca> wrote...
might as well be as insightful as Gwyn and suggest the poster go out
and
buy Knuth just to learn division.
That's not what I said.
No you said
"Look up "multiple precision arithmetic" in any decent text on algorithms,
for example Knuth's "The Art of Computer Programming"."
Where Knuth TAOCP is a COMMERCIAL product [each volume cost
about 65$ CDN].
Compared to say HAC which is freely available on the web [or even say the
LTM textbook].
Your post was not insightful at all. I mod you -1,overrated.

Regular readers of sci.crypt already know that you are an
egotistical fool, but newcomers might be surprised that you
appear not to know or acknowledge that:
(a) one doesn't have to buy a book to look something up in
it; this especially true for standard texts that should be
found in any decent technical library.
(b) Knuth's TAOCP was given as but one example of a
sufficient text on algorithms; surely any programmer worth
his salt must have access to at least one sufficient text that
covers the topic.
(c) anybody seriously interested in programming is well
advised to have, or arrange to have ready access to,
TAOCP for many, many reasons other than long division
algorithms.
(d) used books, including older editions of TAOCP, are
available at a significantly reduced price.
(e) as a learning resource, what I reommended is vastly
superior to your hackery.
(f) nobody asked you to rate my response, which was
brief, accurate, and to the point.
Randy Howard
Posted: Fri Dec 26, 2003 12:56 am
Guest
In article <bsdt9a$mgp$1@ngspool-d02.news.aol.com>, DAGwyn@null.net
says...
Quote:
for example Kunth's "The Art of Computer Programming".

Now, that is an unfortunate typo if ever there was one.

--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: postmaster@sco.com
Randy Howard
Posted: Fri Dec 26, 2003 12:58 am
Guest
In article <R_BGb.82571$2We1.72234@news04.bloor.is.net.cable.rogers.com>,
tomstdenis@iahu.ca says...
Quote:
My possibly quite biased opinion is that the complete
Pascal package in Riesel is easier to read than other
sources.

That's a matter of opinion I guess.

Of course it is. It's okay if you don't all come to the
same conclusions.

Quote:
I'd say my LTM code is very easy to follow.

Since you wrote it, I would hope that you could read it. :-)

Quote:
I have yet to see a library in Ottawa [the capital of Canada I might add]
which is public access and has crypto journals, CS textbooks or anything of
higher academic value.

Try a major University sometime. Anyone of them worth attending should
have very good library facilities.


--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: postmaster@sco.com
Randy Howard
Posted: Fri Dec 26, 2003 1:06 am
Guest
In article <vkJGb.85823$2We1.23318@news04.bloor.is.net.cable.rogers.com>,
tomstdenis@iahu.ca says...
Quote:
Of course if I said the sky was blue and water was wet you'd argue that too
I guess..

Pot, kettle, black?

Every time someone responds to a question in this group, you disagree with
it. Just recently TAOCP was recommended as a source, to which you
disagreed. It's probably one of the very few books other than K&R1 or 2
that can be found in the personal library of almost every serious
professional programmer on the planet. Furthermore, as was said
elsewhere, any decent technical library will have it, in fact most will
have multiple copies.

Somehow, you simply had to disagree with it anyway. Why? Because your
book has a tiny intersection with the contents of TAOCP. Surely that's
not rational. You made your response, as did others. The beauty of
Usenet groups is that people can get the opinions of multiple people
and decide for themselves which to follow. You don't need to police
them all.


--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: postmaster@sco.com
Mok-Kong Shen
Posted: Fri Dec 26, 2003 6:21 am
Guest
Randy Howard wrote:
Quote:


tomstdenis@iahu.ca says...

I have yet to see a library in Ottawa [the capital of Canada I might add]
which is public access and has crypto journals, CS textbooks or anything of
higher academic value.

Try a major University sometime. Anyone of them worth attending should
have very good library facilities.

For information of countrymen of Mr. St Denis: I just
found the contrary to the claimed poverty of the Canadian
public library system. There is, among others, the
National Library of Canada (the counterpart of the US
Library of Congress, I suppose) and there is apparently
good networking. (Given the high status of Canada in
science and technology, a poor public information system
there would have been a wonder indeed.)

M. K. Shen
Tom St Denis
Posted: Fri Dec 26, 2003 8:40 am
Guest
"Randy Howard" <randy.howard@FOOmegapathdslBAR.net> wrote in message
news:MPG.1a558bd1fd71092d989a1c@news.megapathdsl.net...
Quote:
In article <vkJGb.85823$2We1.23318@news04.bloor.is.net.cable.rogers.com>,
tomstdenis@iahu.ca says...
Of course if I said the sky was blue and water was wet you'd argue that
too
I guess..

Pot, kettle, black?

Every time someone responds to a question in this group, you disagree with
it. Just recently TAOCP was recommended as a source, to which you
disagreed. It's probably one of the very few books other than K&R1 or 2
that can be found in the personal library of almost every serious
professional programmer on the planet. Furthermore, as was said
elsewhere, any decent technical library will have it, in fact most will
have multiple copies.

Somehow, you simply had to disagree with it anyway. Why? Because your
book has a tiny intersection with the contents of TAOCP. Surely that's
not rational. You made your response, as did others. The beauty of
Usenet groups is that people can get the opinions of multiple people
and decide for themselves which to follow. You don't need to police
them all.

The dude wants to know how todo division. You don't buy a 65$ text book to
learn that unless you got money to burn. For the record, vol2 [the one he
would have to buy] covers others topics such as floating point math, random
number generators, statistical testing, etc.

It's as if the guy asked what the first value of the AES sbox is and he
recommended that he buys the Rijndael book.

I say if good free alternatives exist you offer those first and then get
into the $$$ alternatives. I even recommended HAC above my book so this
isn't an ego trip this is just pure realism.

Tom
Tom St Denis
Posted: Fri Dec 26, 2003 8:47 am
Guest
"Randy Howard" <randy.howard@FOOmegapathdslBAR.net> wrote in message
news:MPG.1a5589f916715c21989a1b@news.megapathdsl.net...
Quote:
I have yet to see a library in Ottawa [the capital of Canada I might
add]
which is public access and has crypto journals, CS textbooks or anything
of
higher academic value.

Try a major University sometime. Anyone of them worth attending should
have very good library facilities.

Tom no in university. University libraries are not free to just anyone, tom
no have $$$ to burn.

Simple.

Still the point is if free stuff exists on the web [GMP, the HAC book, LTM,
etc...] that's a better place to start than with a CC and Amazon.com

Tom
Arnold Stang
Posted: Fri Dec 26, 2003 9:26 am
Guest
Randy Howard wrote:
Quote:
In article <vkJGb.85823$2We1.23318@news04.bloor.is.net.cable.rogers.com>,
tomstdenis@iahu.ca says...

Of course if I said the sky was blue and water was wet you'd argue that too
I guess..


Pot, kettle, black?

Every time someone responds to a question in this group, you disagree with
it. Just recently TAOCP was recommended as a source, to which you
disagreed. It's probably one of the very few books other than K&R1 or 2
that can be found in the personal library of almost every serious
professional programmer on the planet. Furthermore, as was said
elsewhere, any decent technical library will have it, in fact most will
have multiple copies.

Somehow, you simply had to disagree with it anyway. Why? Because your
book has a tiny intersection with the contents of TAOCP. Surely that's
not rational. You made your response, as did others. The beauty of
Usenet groups is that people can get the opinions of multiple people
and decide for themselves which to follow. You don't need to police
them all.


Tom St. Denis is a disturbed youth who desperately needs help. I hope

someone at his community college can take him under his/her wing and
give him the counseling he needs. Sincerely.

Arnold Stang
Tom St Denis
Posted: Fri Dec 26, 2003 9:38 am
Guest
"Arnold Stang" <stang13@anonymous.to> wrote in message
news:nyXGb.3117$lt.353@nwrdny02.gnilink.net...
Quote:
Tom St. Denis is a disturbed youth who desperately needs help. I hope
someone at his community college can take him under his/her wing and
give him the counseling he needs. Sincerely.

Tom St Denis contributions to the fields of CS, Math and Cryptography: A
few. More the average poster.

Arnold Stang contributions to the fields of CS, Math and Cryptography:
ZERO.

It's easy to badmouth people. It's harder to contribute things without
demanding anything in return. In otherwords, put up or shut up.

Tom

[And no, I don't think contributing something gives someone the right to
disrespect others. My point is if all you ever post are flames and you
never contribute to the group you really don't have any credibility. At
least when I reply to people in the negative it's because I probably have
experience in the subject that makes me qualified to post].
 
Page 2 of 5    Goto page Previous  1, 2, 3, 4, 5  Next   All times are GMT - 5 Hours
The time now is Tue Oct 07, 2008 4:14 pm