Dealing with a large integer

M

Mark McIntyre

Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it.

This is such an easy challenge to defeat, I won't embarrass you.
[well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]

Quite.
Mark McIntyre
 
M

Mark McIntyre

[email protected] (Walter Roberson) said:
Post code that you think safely uses gets and i'll prove it wrong within
the context of the API you are using to "ensure" it. [well, i'm hoping
you're using the unix api, since i wouldn't have the first clue about
any other one]

How about something like this:

Open a file w+. Write known data into it. fseek() back to the
beginning of the file. gets() with a buffer at least as big as
the data to be written.

gets() reads from stdin. You'll have to use freopen() to replace
stdin by your file. Seems like a pretty big stretch to make just
to use gets() safely, when you could just use a better designed
function instead.

Nobody's arguing that its sensible to use gets(), merely with the
assertion that its "impossible" to use safely, even in a controlled
envrionment.

Heck if nuclear waste and anthrax can be safe, in the right
environment then ...
Mark McIntyre
 
Y

yong

russell said:
yong said:
Hi all
I have an large integer in this format

[lemm call this X:]
x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6
now I must convert it to this format
[Y:]

y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5
x1-x5 is given.I must get y1-y4 from it.
How can I do this on my 32bit PC?
Sorry for that my English is poor.
Thanks.



Some kind of pdf encoder, eh?


There's probably a lot of literature on smart tricks, but
the basic idea (beside simply using 64-bit integers and brute force --
BTW even 32-bit PC's can do h/w 64-bit arith these days) is to note that

X % 900 = Y % 900 = y4.

Then we see that
256^5 % 900 = 376
256^4 % 900 = 796
256^3 % 900 = 316
256^2 % 900 = 736
256^1 % 900 = 256

So we must have y4 = (376*x1 + 796*x2 + 316*x3 + 736*x4 + 256*x5 + x6) % 900 .
(Look, maw, only 16-bit arithmetic!)

Similiarly for the other y_i.

Thanks.

It's really a good idea. :]
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top