J2ME BigInteger class gives incorrect results

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

J2ME BigInteger class gives incorrect results

faissal bensefia
Hello!
I'm currently making use of the modPow() method of the BigInteger
class from the J2ME library and have found that it provides results
that differ - often significantly - from the J2SE BigInteger
implementation. One example is as follows:
My base is:
0x915d75c15139e59c085b0e5c31721c9f2146c75eec5ac983081dc313cc6ec0ea9900000008000000004a1fc07f000000080000000066c9c8e70000003878343bfb528ac97d5e9d00b4ac823aba05157922af70b3bf998ba7ba338d7c24c7be99658abcfd174ab6696d3812a90bf6feb4fd697a5a4aa37924a10d08360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
My exponent is:
0x10001
My modulus is:
MODULUS: 0xc150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e3ae97d95c8b19442b3c0a10d8f5633fecedd6926a7f6dab0ddb7d457f9ea81b8465fcd6fffeed114011df91c059caedaf97625f6c96ecc74725556934ef781d866b34f011fce4d835a090196e9a5f0e4449af7eb697ddb9076494ca5f81104a305b6dd27665722c46b60e5df680fb16b210607ef217652e60236c255f6a28315f4083a96791d7214bf64c1df4fd0db1944fb26a2a57031b32eee64ad15a8ba68885cde74a5bfc920f6abf59ba5c75506373e7130f9042da922179251f
The result in the J2ME library is:
0x1687773b3bbc62767d9c54837976187a97351cd3ea66033c79067251549fddbbca98a33f43b54c700a1dd4a8d78474f05980f0eebd7612cdeb762b3b7a5849d278602ba5b0858fbca2cecd106a817bdf6a133c7547195e02131b3b96988f0286a84e9db92f59df88fd8799d653173c01a8d17033655821d2ecb48e3a33ed32693fdf16ddbd2a5a598d01ac4520d9f12b67b7f8ba30714a3129eba4118b9a2afba814623ff82d1f30322d11acfeb18bf2bbcd9d1f216de581001d3dc8e964d111b82ff5e3a380d907353179d751d967b662a025df8d6a2b5fe4a58ef2ffc5ad1bee1fa83de3db785b3464804862402a4d53e6cd75932557d10ada9eee9759918a
The J2SE result however is:
0x4c2d216337bd281a33ddb7d4e9e8441d808876ed2e3139362ee5c8ed440093a5948ce4f5365072fb7336f5eef5ea5430eba80ee669076d42933f52add71d5682adda24e563d46016fa40d7b005d92ad4d98c637e7e01ae49fdefe1fab6ad5dfc4f74a998b6eec80fe797a21e573d90a17e0aa1839a5b088da93b248466eab875c9b565f4eb21857ee30281aa46063a0b89ec0b2d3c9fb3db82d6f2f77ef1b1ea33261ef819757e2354326bc5039f6ed0fa54200eadc31a74690f7d42152a678323efb4f0fd621e11dfc871bb273e714f6f6883175d7a9fccaa011f12918b3af04a703f8ba8173fd8e3a6c77dc4c95fc7d1666f2609c19fa0f01eee86b1dd82d1

Although I understand that J2ME is often regarded as thoroughly
obsolete, I would nonetheless greatly appreciate any help.

Regards,
~Faissal

Reply | Threaded
Open this post in threaded view
|

Re: J2ME BigInteger class gives incorrect results

Peter Dettman-3
Hi Faissal,
I'm unable to reproduce this for the current J2ME BigInteger
implementation, nor for any version in the last 7 years. They all give
the same result as J2SE (OpenJDK 12.0.2).

Please double-check your tests. If you still think there is a problem,
then you will need to give more details. Please open an issue at github:
https://github.com/bcgit/bc-java .

One possibility is that you are encountering a bug in the Java runtime
on whatever device you are using. Please mention the device, the OS, the
Java runtime version and any other relevant details. Consider running
your test also on other platforms for comparison.

Regards,
Pete Dettman


On 9/6/20 4:13 am, faissal bensefia wrote:

> Hello!
> I'm currently making use of the modPow() method of the BigInteger
> class from the J2ME library and have found that it provides results
> that differ - often significantly - from the J2SE BigInteger
> implementation. One example is as follows:
> My base is:
> 0x915d75c15139e59c085b0e5c31721c9f2146c75eec5ac983081dc313cc6ec0ea9900000008000000004a1fc07f000000080000000066c9c8e70000003878343bfb528ac97d5e9d00b4ac823aba05157922af70b3bf998ba7ba338d7c24c7be99658abcfd174ab6696d3812a90bf6feb4fd697a5a4aa37924a10d08360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> My exponent is:
> 0x10001
> My modulus is:
> MODULUS: 0xc150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e3ae97d95c8b19442b3c0a10d8f5633fecedd6926a7f6dab0ddb7d457f9ea81b8465fcd6fffeed114011df91c059caedaf97625f6c96ecc74725556934ef781d866b34f011fce4d835a090196e9a5f0e4449af7eb697ddb9076494ca5f81104a305b6dd27665722c46b60e5df680fb16b210607ef217652e60236c255f6a28315f4083a96791d7214bf64c1df4fd0db1944fb26a2a57031b32eee64ad15a8ba68885cde74a5bfc920f6abf59ba5c75506373e7130f9042da922179251f
> The result in the J2ME library is:
> 0x1687773b3bbc62767d9c54837976187a97351cd3ea66033c79067251549fddbbca98a33f43b54c700a1dd4a8d78474f05980f0eebd7612cdeb762b3b7a5849d278602ba5b0858fbca2cecd106a817bdf6a133c7547195e02131b3b96988f0286a84e9db92f59df88fd8799d653173c01a8d17033655821d2ecb48e3a33ed32693fdf16ddbd2a5a598d01ac4520d9f12b67b7f8ba30714a3129eba4118b9a2afba814623ff82d1f30322d11acfeb18bf2bbcd9d1f216de581001d3dc8e964d111b82ff5e3a380d907353179d751d967b662a025df8d6a2b5fe4a58ef2ffc5ad1bee1fa83de3db785b3464804862402a4d53e6cd75932557d10ada9eee9759918a
> The J2SE result however is:
> 0x4c2d216337bd281a33ddb7d4e9e8441d808876ed2e3139362ee5c8ed440093a5948ce4f5365072fb7336f5eef5ea5430eba80ee669076d42933f52add71d5682adda24e563d46016fa40d7b005d92ad4d98c637e7e01ae49fdefe1fab6ad5dfc4f74a998b6eec80fe797a21e573d90a17e0aa1839a5b088da93b248466eab875c9b565f4eb21857ee30281aa46063a0b89ec0b2d3c9fb3db82d6f2f77ef1b1ea33261ef819757e2354326bc5039f6ed0fa54200eadc31a74690f7d42152a678323efb4f0fd621e11dfc871bb273e714f6f6883175d7a9fccaa011f12918b3af04a703f8ba8173fd8e3a6c77dc4c95fc7d1666f2609c19fa0f01eee86b1dd82d1
>
> Although I understand that J2ME is often regarded as thoroughly
> obsolete, I would nonetheless greatly appreciate any help.
>
> Regards,
> ~Faissal
>


Reply | Threaded
Open this post in threaded view
|

Re: J2ME BigInteger class gives incorrect results

faissal bensefia
Hi Peter,
Apologies for making you do all that work, in case anyone else has the
same issue it turns out I wrote:
  new BigInteger(data)
instead of:
  new BigInteger(1, data)

Regards,
~Faissal

On Wed, Jun 10, 2020 at 7:51 AM Peter Dettman
<[hidden email]> wrote:

>
> Hi Faissal,
> I'm unable to reproduce this for the current J2ME BigInteger
> implementation, nor for any version in the last 7 years. They all give
> the same result as J2SE (OpenJDK 12.0.2).
>
> Please double-check your tests. If you still think there is a problem,
> then you will need to give more details. Please open an issue at github:
> https://github.com/bcgit/bc-java .
>
> One possibility is that you are encountering a bug in the Java runtime
> on whatever device you are using. Please mention the device, the OS, the
> Java runtime version and any other relevant details. Consider running
> your test also on other platforms for comparison.
>
> Regards,
> Pete Dettman
>
>
> On 9/6/20 4:13 am, faissal bensefia wrote:
> > Hello!
> > I'm currently making use of the modPow() method of the BigInteger
> > class from the J2ME library and have found that it provides results
> > that differ - often significantly - from the J2SE BigInteger
> > implementation. One example is as follows:
> > My base is:
> > 0x915d75c15139e59c085b0e5c31721c9f2146c75eec5ac983081dc313cc6ec0ea9900000008000000004a1fc07f000000080000000066c9c8e70000003878343bfb528ac97d5e9d00b4ac823aba05157922af70b3bf998ba7ba338d7c24c7be99658abcfd174ab6696d3812a90bf6feb4fd697a5a4aa37924a10d08360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> > My exponent is:
> > 0x10001
> > My modulus is:
> > MODULUS: 0xc150023e2f70db7985ded064759cfecf0af328e69a41daf4d6f01b538135a6f91f8f8b2a0ec9ba9720ce352efcf6c5680ffc424bd634864902de0b4bd6d49f4e580230e3ae97d95c8b19442b3c0a10d8f5633fecedd6926a7f6dab0ddb7d457f9ea81b8465fcd6fffeed114011df91c059caedaf97625f6c96ecc74725556934ef781d866b34f011fce4d835a090196e9a5f0e4449af7eb697ddb9076494ca5f81104a305b6dd27665722c46b60e5df680fb16b210607ef217652e60236c255f6a28315f4083a96791d7214bf64c1df4fd0db1944fb26a2a57031b32eee64ad15a8ba68885cde74a5bfc920f6abf59ba5c75506373e7130f9042da922179251f
> > The result in the J2ME library is:
> > 0x1687773b3bbc62767d9c54837976187a97351cd3ea66033c79067251549fddbbca98a33f43b54c700a1dd4a8d78474f05980f0eebd7612cdeb762b3b7a5849d278602ba5b0858fbca2cecd106a817bdf6a133c7547195e02131b3b96988f0286a84e9db92f59df88fd8799d653173c01a8d17033655821d2ecb48e3a33ed32693fdf16ddbd2a5a598d01ac4520d9f12b67b7f8ba30714a3129eba4118b9a2afba814623ff82d1f30322d11acfeb18bf2bbcd9d1f216de581001d3dc8e964d111b82ff5e3a380d907353179d751d967b662a025df8d6a2b5fe4a58ef2ffc5ad1bee1fa83de3db785b3464804862402a4d53e6cd75932557d10ada9eee9759918a
> > The J2SE result however is:
> > 0x4c2d216337bd281a33ddb7d4e9e8441d808876ed2e3139362ee5c8ed440093a5948ce4f5365072fb7336f5eef5ea5430eba80ee669076d42933f52add71d5682adda24e563d46016fa40d7b005d92ad4d98c637e7e01ae49fdefe1fab6ad5dfc4f74a998b6eec80fe797a21e573d90a17e0aa1839a5b088da93b248466eab875c9b565f4eb21857ee30281aa46063a0b89ec0b2d3c9fb3db82d6f2f77ef1b1ea33261ef819757e2354326bc5039f6ed0fa54200eadc31a74690f7d42152a678323efb4f0fd621e11dfc871bb273e714f6f6883175d7a9fccaa011f12918b3af04a703f8ba8173fd8e3a6c77dc4c95fc7d1666f2609c19fa0f01eee86b1dd82d1
> >
> > Although I understand that J2ME is often regarded as thoroughly
> > obsolete, I would nonetheless greatly appreciate any help.
> >
> > Regards,
> > ~Faissal
> >
>
>