Code Monkey home page Code Monkey logo

libnum's People

Contributors

allanlw avatar avamsi avatar hellman avatar kur0mi avatar nneonneo avatar sayoojsamuel avatar warnerjon12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libnum's Issues

PKCS#7

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

Modular square root by power of 2

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]

Cannot be installed from a relative path

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

len_in_bits is inaccurate

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?

linux+python2 error

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.