Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build Wheel

on:
push:
branches: [main, master]
tags:
- "v*"
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install build backend
run: python -m pip install --upgrade pdm-backend build

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.lock
pip install pytest

- name: Run tests with pytest
run: pytest

- name: Build wheel
run: python -m build --wheel

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: |
dist/*.whl
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13.2
10 changes: 10 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

167 changes: 0 additions & 167 deletions libnum/ecc.py

This file was deleted.

24 changes: 11 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
[project]
name = "libnum"
version = "1.7.1"
version = "1.7.2"
description = "Working with numbers (primes, modular, etc.)"
authors = ["hellman"]
authors = [{ "name" = "hellman" }]
license = "MIT"
readme = "README.md"
keywords = ["numbers", "modular", "cryptography", "number theory"]
Expand All @@ -11,15 +11,13 @@ classifiers = [
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Security :: Cryptography',
]

[tool.poetry.urls]
homepage = "http://github.com/hellman/libnum"

[tool.poetry.dependencies]
python = "^3.4"

[tool.poetry.dev-dependencies]
dependencies = []
requires-python = ">= 3.6"

[build-system]
requires = ["poetry-core>=1.0.0a5"]
build-backend = "poetry.core.masonry.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.rye]
managed = true
dev-dependencies = ["pytest>=8.3.5"]
19 changes: 19 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false
# generate-hashes: false
# universal: false

-e file:.
iniconfig==2.1.0
# via pytest
packaging==25.0
# via pytest
pluggy==1.5.0
# via pytest
pytest==8.3.5
12 changes: 12 additions & 0 deletions requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false
# generate-hashes: false
# universal: false

-e file:.
10 changes: 5 additions & 5 deletions libnum/__init__.py → src/libnum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
# commonly used things
from fractions import Fraction

from .primes import *
from .factorize import *
from . import ecc
from .chains import *
from .common import *
from .factorize import *
from .modular import *
from .primes import *
from .sqrtmod import *
from .stuff import *
from .strings import *
from .chains import *
from . import ecc
from .stuff import *


# TODO: Add doctest after we have better docs
22 changes: 12 additions & 10 deletions libnum/chains.py → src/libnum/chains.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from libnum import nroot, gcd, Fraction
from fractions import Fraction

from .common import gcd, nroot

class Chain(object):

class Chain:
def __init__(self, *args):
self._chain = []
self._frac = None
Expand All @@ -15,11 +17,11 @@ def _calcFrac(self):
r = Fraction(0, 1)
for x in reversed(self.chain):
r = Fraction(1, x + r)
return 1/r
return 1 / r

def _calcChain(self):
r = []
a, b = self.frac.numerator, self.frac.denominator
a, b = self.frac.numerator, self.frac.denominator # type: ignore
while b != 1:
r.append(a / b)
a, b = b, a % b
Expand Down Expand Up @@ -63,9 +65,9 @@ def convergents(self):


def sqrt_chained_fractions(n, limit=None):
'''
"""
E.g. sqrt_chained_fractions(13) = [3,(1,1,1,1,6)]
'''
"""
s = nroot(n, 2)
if s**2 == n:
return [s]
Expand All @@ -90,21 +92,21 @@ def sqrt_chained_fractions(n, limit=None):


def _sqrt_iter(n, s, t, a, b):
'''
"""
take t*(sqrt(n)+a)/b
s = floor(sqrt(n))
return (v, next fraction params t, a, b)
'''
"""
v = t * (s + a) // b
t2 = b
b2 = t * (n - (b * v - a)**2)
b2 = t * (n - (b * v - a) ** 2)
a2 = b * v - a
g = gcd(t2, b2)
t2 //= g
b2 //= g
return v, (t2, a2, b2)


if __name__ == '__main__':
if __name__ == "__main__":
for v in (2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 1337, 31337):
print("sqrt(%d): %s" % (v, repr(sqrt_chained_fractions(v))))
Loading