1 parent
d44611f39b
commit
305c6fea94
2 files changed
+10
-15
No files matched your search
@@ -1,3 +1,6 @@
|
|||||||
|
from proto_rsa import LdaRsahh
|
||||||
|
|
||||||
|
|
||||||
def e1():
|
def e1():
|
||||||
s = "flow"
|
s = "flow"
|
||||||
|
|
||||||
@@ -14,9 +17,6 @@ def e2():
|
|||||||
return dec_ascii(i)
|
return dec_ascii(i)
|
||||||
|
|
||||||
|
|
||||||
from proto_rsa import LdaRsahh
|
|
||||||
|
|
||||||
|
|
||||||
def e3():
|
def e3():
|
||||||
a = LdaRsahh(p=251, q=191, e=65537).enc(26729)
|
a = LdaRsahh(p=251, q=191, e=65537).enc(26729)
|
||||||
|
|
||||||
|
|||||||
+7
-12
@@ -1,11 +1,10 @@
|
|||||||
def inv(a, n):
|
|
||||||
return pow(a, -1, n)
|
|
||||||
|
|
||||||
|
|
||||||
import math
|
import math
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
import warnings
|
|
||||||
|
|
||||||
|
def inv(a, n):
|
||||||
|
return pow(a, -1, n)
|
||||||
|
|
||||||
|
|
||||||
class LdaRsahh:
|
class LdaRsahh:
|
||||||
@@ -18,18 +17,14 @@ class LdaRsahh:
|
|||||||
ln_ops: Callable[[int, int], int] | None = None,
|
ln_ops: Callable[[int, int], int] | None = None,
|
||||||
):
|
):
|
||||||
# operator.mul or math.lcm
|
# operator.mul or math.lcm
|
||||||
self._lnops = ln_ops or math.lcm
|
self._lnops: Callable[[int, int], int] = ln_ops or math.lcm
|
||||||
self._p, self._q = p, q
|
self._p, self._q = p, q
|
||||||
if d is None and e is None:
|
if d is None and e is None:
|
||||||
raise ValueError("at least d or e needs to be math.gcd(e, phi)fed in")
|
raise ValueError("at least d or e needs to be fed in")
|
||||||
ln = self.ln
|
ln = self.ln
|
||||||
if e is None:
|
if e is None:
|
||||||
e = inv(d, ln)
|
e = inv(d, ln)
|
||||||
if not 1 < e < ln:
|
elif not 1 < e < ln:
|
||||||
warnings.warn(
|
|
||||||
f"{e = }, {ln = }, 1 < e < ln not satisfied, e rebinds to e % ln",
|
|
||||||
UserWarning,
|
|
||||||
)
|
|
||||||
e %= ln
|
e %= ln
|
||||||
if not 1 < e < ln:
|
if not 1 < e < ln:
|
||||||
raise ValueError(f"{e = }, {ln = }, 1 < e < ln not satisfied")
|
raise ValueError(f"{e = }, {ln = }, 1 < e < ln not satisfied")
|
||||||
|
|||||||
Reference in new issue
Block a user