The Museum of HP Calculators

HP Forum Archive 20

[ Return to Index | Top of Index ]

Possible bug in WP34s with big integers
Message #1 Posted by Neil Hamilton (Ottawa) on 22 June 2011, 12:30 p.m.

I was working at generating toy RSA keys for algorithm exploration and created 2 32-bit primes (P and Q). I decremented each one in 2c64 mode and multiplied them together to get N = (P-1)(Q-1).

However, the number I get is missing the MSbit.

On VERS 1145:

With R77 = 0xF138552D (a prime) and R78 = 0xAAC9B7A5 (a prime)

001 LBL A
002 WSIZE 64
003 2COMPL
004 BASE 16
005 RCL 77
006 DEC X
007 RCL 78
008 DEC X
009 [times]
010 RTN

The answer WP34s gives is: 0x20ED7AD3E4850430.

In BC:

ibase=2^4
obase=2^4
p=F138552D
q=AAC9B7A5
n=(p-1)*(q-1)
n
A0ED7AD3E4850430 (This is correct. The MSbit should be set.)

I also repeated this in 1c64 mode with the same result. Any ideas? Have I overflowed something? I think this value should have been within range of [1-2]c64.

Best regards...

      
Re: Possible bug in WP34s with big integers
Message #2 Posted by Neil Hamilton (Ottawa) on 22 June 2011, 2:26 p.m.,
in response to message #1 by Neil Hamilton (Ottawa)

Oops! That's obviously phi(n) not n but still likely a bug. :-)

      
Re: Possible bug in WP34s with big integers
Message #3 Posted by Jake Schwartz on 22 June 2011, 4:08 p.m.,
in response to message #1 by Neil Hamilton (Ottawa)

Quote:
The answer WP34s gives is: 0x20ED7AD3E4850430.

....and leaving the overflow flag set. Since the MSB is the sign, the value would not be able to be represented in only 63 bits and if the MSB was able to be set, the value would erroneously go negative. If you run the program in the 34S and receive 20ED 7AD3 E485 0430 as a result, then get the leading hex digit to become an A by the following: 100000000000 ENTER 10000 * + 100000000000 ENTER 70000 * +, switching to decimal generates -6,850,684,407,670,045,648. Also, doing the problem in unsigned mode results in a decimal value of 11,596,059,666,039,505,968. The log(base 2) of this value is 63.33..., so since more than 63 bits would be needed to represent it, the signed 64-bit modes could not hold it. I think the 34S is okay.

Jake

Jake

            
Re: Possible bug in WP34s with big integers
Message #4 Posted by Neil Hamilton (Ottawa) on 22 June 2011, 4:28 p.m.,
in response to message #3 by Jake Schwartz

Argh! You are so right! I had meant to set unsigned mode.

It works now that I have done that.

Thanks a bunch!!

      
Re: Possible bug in WP34s with big integers
Message #5 Posted by Marcus von Cube, Germany on 22 June 2011, 4:27 p.m.,
in response to message #1 by Neil Hamilton (Ottawa)

I just tested it in unsigned mode and the result is as you expected.

      
Re: Possible bug in WP34s with big integers
Message #6 Posted by Paul Dale on 22 June 2011, 4:46 p.m.,
in response to message #1 by Neil Hamilton (Ottawa)

This isn't a bug as folks have already identified: negative * negative gives positive. If the now not so recent change to bring multiplication sign handling into line with the 16c wasn't made, I think the answer would have been what you expected.

- Pauli


[ Return to Index | Top of Index ]

Go back to the main exhibit hall