Projet

Général

Profil

0001-pycrict-initial-utils-functions.patch

Paul Marillonnet, 16 mars 2018 17:57

Télécharger (3,98 ko)

Voir les différences:

Subject: [PATCH] pycrict: initial utils functions

 pycrict/README              |  5 +++++
 pycrict/pycrict/__init__.py |  0
 pycrict/pycrict/rsa.py      | 10 ++++++++++
 pycrict/pycrict/settings.py |  2 ++
 pycrict/pycrict/utils.py    | 29 +++++++++++++++++++++++++++++
 pycrict/setup.py            | 24 ++++++++++++++++++++++++
 pycrict/tests/testutils.py  | 16 ++++++++++++++++
 7 files changed, 86 insertions(+)
 create mode 100644 pycrict/README
 create mode 100644 pycrict/pycrict/__init__.py
 create mode 100644 pycrict/pycrict/rsa.py
 create mode 100644 pycrict/pycrict/settings.py
 create mode 100644 pycrict/pycrict/utils.py
 create mode 100755 pycrict/setup.py
 create mode 100755 pycrict/tests/testutils.py
pycrict/README
1
Pedagogical purpose only
2

  
3
Python (re-)implementation of the cryptographic features offered by Cryptic
4

  
5
author: pmarillonnet(at)entrouvert(dot)com
pycrict/pycrict/rsa.py
1
import utils
2

  
3
def generate_key_pair(): # todo
4
    pass
5

  
6
def encrypt_rsa(m, e, n): # todo
7
    pass
8

  
9
def decrypt_rsa(m, d, n): # todo
10
    pass
pycrict/pycrict/settings.py
1
RANDOM_PRIME_LENGTH=10
2
RANDOM_PRIME_ELECTION_TRIES=5*pow(10,9)
pycrict/pycrict/utils.py
1
from random import randint
2
from math import sqrt
3

  
4
def rabin_miller(prime): # todo
5
    pass
6

  
7
def possible_factors(c):
8
    yield 2
9
    i = 3
10
    while i < sqrt(c):
11
        yield i
12
        i = i+2
13

  
14
def is_prime(c):
15
    for i in possible_factors(c):
16
        if c%i == 0:
17
            return False
18
    return True
19

  
20
def get_random_prime():
21
    is_prime = False
22
    p_length = settings.RANDOM_PRIME_LENGTH
23
    ntries = 0
24

  
25
    while not is_prime and n < settings.RANDOM_PRIME_ELECTION_TRIES:
26
        candidate = randint(pow(10, p_length), pow(10, p_length+1))
27
        if is_prime(candidate):
28
            return candidate
29
        n = n+1
pycrict/setup.py
1
#!/usr/bin/env python
2

  
3
from setuptools import setup, find_packages
4

  
5
import pycrict
6

  
7
setup(
8
    name='pycrict',
9
    packages=find_packages(),
10
    author='Paul M.',
11
    author_email='paul@nowhere.null',
12
    description='Paul\'s simple crypto module',
13
    long_description=open('README').read(),
14
    include_package_data=False,
15
    classifiers=[
16
        "Programming Language :: Python",
17
        "Development Status :: 1 - Planning",
18
        "License :: OSI Approved",
19
        "Natural Language :: English",
20
        "Operating System :: OS Independent",
21
        "Programming Language :: Python :: 2.7",
22
        "Topic :: Software Development :: Libraries :: Python Modules",
23
    ]
24
)
pycrict/tests/testutils.py
1
#!/usr/bin/python
2

  
3
from pycrict import utils
4

  
5
#todo pytestify
6

  
7
def test_is_prime():
8
    assert utils.is_prime(523)
9
    assert not utils.is_prime(527)
10
    assert utils.is_prime(6491)
11
    assert not utils.is_prime(6707)
12
    assert utils.is_prime(5483983)
13
    assert not utils.is_prime(5483987)
14

  
15
test_is_prime()
16
print 'everything is fine'
0
-