hellman / libnum Goto Github PK
View Code? Open in Web Editor NEWWorking with numbers (primes, modular, etc.)
Working with numbers (primes, modular, etc.)
Will you be adding support for Python 3 in this?
This could be useful (I needed it just now)
I'm new to python so you may want to rewrite this.
def pkcs7(s, b):
if len(s) % b == 0:
return s
need = len(s) / b + 1
byte = need*b - len(s)
return s + chr(byte)*byte
Function sqrtmod_prime_power
appears to fail when the modular is a power of 2 instead of a power of an odd prime:
>>> list(libnum.sqrtmod_prime_power(3, 2, 3))
[7, 5, 1, 3]
>>> list(libnum.sqrtmod_prime_power(1, 2, 3))
[1, 3, 5, 7]
Here it erroneously found the same solutions for the equations x**2 == 3 (mod 8)
and x**2 == 1 (mod 8)
.
The same wrong result is returned with sqrtmod
as well:
>>> list(libnum.sqrtmod(3, {2: 3}))
[7, 5, 1, 3]
python libnum\setup.py install
Fails
running install
running build
running build_py
package init file 'libnum\__init__.py' not found (or not a regular file)
creating build
creating build\lib
creating build\lib\libnum
copying libnum\setup.py -> build\lib\libnum
error: package directory 'libnum\chains' does not exist
Going to the directory itself then running
python setup.py install
Succeeds
math.log(n, 2)
doesn't produce exact results for large numbers, so numbers near a power of 2 can be returned incorrectly. The first example is:
In [43]: (140737488355328).bit_length()
Out[43]: 48
In [44]: len_in_bits(140737488355328)
Out[44]: 47
http://stackoverflow.com/q/9829578/125507
http://stackoverflow.com/q/2654149/125507
this is what I used in scipy to find the next hamming number:
try:
return n.bit_length()
except AttributeError:
# Fallback for Python <2.7
return len(bin(n)) - 2
The fallback uses string processing, but this is fast because string operations are compiled C?
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import libnum
libnum.s2n("abcd")
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/libnum/strings.py", line 10, in s2n
return int(s.encode("utf-8").hex(), 16)
AttributeError: 'str' object has no attribute 'hex'
Polynomial in finite field might be important in number theory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.