Skip to content

convert to and from binary #116

@thestick613

Description

@thestick613

Where did this functionality go? I'm aware of gmpy2.from_binary and gmpy2.to_binary, but i need the gmpy behavior. I want to speedup some RSA sign and verify code.

In [1]: from gmpy import mpz

In [2]: n = mpz(12345)

In [3]: n.binary()
Out[3]: '90'

In [4]: mpz('90', 256)
Out[4]: mpz(12345)

In [5]: from gmpy2 import mpz

In [6]: n = mpz(12345)

In [7]: import gmpy2

In [8]: gmpy2.to_binary(n)
Out[8]: '\x01\x0190'

In [9]: gmpy2.from_binary('\x01\x0190')
Out[9]: mpz(12345)

In [10]: mpz('90', 256)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-6d09b478991e> in <module>()
----> 1 mpz('90', 256)

ValueError: base for mpz() must be 0 or in the interval 2 ... 62

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions