mlymath 0.2.0__tar.gz → 0.3.0b2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mlymath-0.2.0 → mlymath-0.3.0b2}/PKG-INFO +14 -2
- {mlymath-0.2.0 → mlymath-0.3.0b2}/README.md +13 -1
- mlymath-0.3.0b2/RSA/RSA.py +73 -0
- mlymath-0.3.0b2/RSA/__init__.py +13 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/math/__init__.py +2 -8
- {mlymath-0.2.0 → mlymath-0.3.0b2}/math/math.py +0 -61
- {mlymath-0.2.0 → mlymath-0.3.0b2}/mlymath.egg-info/PKG-INFO +14 -2
- {mlymath-0.2.0 → mlymath-0.3.0b2}/mlymath.egg-info/SOURCES.txt +4 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/mlymath.egg-info/top_level.txt +2 -0
- mlymath-0.3.0b2/mod/__init__.py +21 -0
- mlymath-0.3.0b2/mod/mod.py +36 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/setup.py +1 -1
- {mlymath-0.2.0 → mlymath-0.3.0b2}/mlymath.egg-info/dependency_links.txt +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/morse/__init__.py +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/morse/morse.py +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/puzzle/__init__.py +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/puzzle/puzzle.py +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/setup.cfg +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/sort/__init__.py +0 -0
- {mlymath-0.2.0 → mlymath-0.3.0b2}/sort/sort.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mlymath
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0b2
|
4
4
|
Summary: 一个用于数学计算的Python库
|
5
5
|
Author: mly
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
@@ -46,10 +46,13 @@ Dynamic: summary
|
|
46
46
|
- min(\*nums, n): 找到多个数中第 N 小的数, 输入n时请注意使用n = [num]
|
47
47
|
- list_min_index(nums, n): 找到数组中第 N 小的数的索引
|
48
48
|
- min_index(\*nums, n): 找到多个数中第 N 小的数的索引, 输入n时请注意使用n = [num]
|
49
|
+
- math_help() -> None: 显示math帮助信息
|
50
|
+
- mlymath.RSA RSA
|
49
51
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
50
52
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
51
53
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
52
|
-
-
|
54
|
+
- RSA_help(): 显示帮助信息
|
55
|
+
|
53
56
|
- mlymath.sort 排序模块
|
54
57
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
55
58
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -74,6 +77,15 @@ Dynamic: summary
|
|
74
77
|
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
75
78
|
- 如果无解,则返回空字符串。
|
76
79
|
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
80
|
+
- mlymath.mod 整除特征模块
|
81
|
+
- mod2(n): 判断 n 是否能被 2 整除。
|
82
|
+
- mod3(n): 判断 n 是否能被 3 整除。
|
83
|
+
- mod4(n): 判断 n 是否能被 4 整除。
|
84
|
+
- mod5(n): 判断 n 是否能被 5 整除。
|
85
|
+
- mod6(n): 判断 n 是否能被 6 整除。
|
86
|
+
- mod7(n): 判断 n 是否能被 7 整除。
|
87
|
+
- mod8(n): 判断 n 是否能被 8 整除。
|
88
|
+
- mod9(n): 判断 n 是否能被 9 整除。
|
77
89
|
#### mly万岁!!!🎉
|
78
90
|
#### mly万岁!!!🎉
|
79
91
|
#### mly万岁!!!🎉
|
@@ -29,10 +29,13 @@
|
|
29
29
|
- min(\*nums, n): 找到多个数中第 N 小的数, 输入n时请注意使用n = [num]
|
30
30
|
- list_min_index(nums, n): 找到数组中第 N 小的数的索引
|
31
31
|
- min_index(\*nums, n): 找到多个数中第 N 小的数的索引, 输入n时请注意使用n = [num]
|
32
|
+
- math_help() -> None: 显示math帮助信息
|
33
|
+
- mlymath.RSA RSA
|
32
34
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
33
35
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
34
36
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
35
|
-
-
|
37
|
+
- RSA_help(): 显示帮助信息
|
38
|
+
|
36
39
|
- mlymath.sort 排序模块
|
37
40
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
38
41
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -57,6 +60,15 @@
|
|
57
60
|
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
58
61
|
- 如果无解,则返回空字符串。
|
59
62
|
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
63
|
+
- mlymath.mod 整除特征模块
|
64
|
+
- mod2(n): 判断 n 是否能被 2 整除。
|
65
|
+
- mod3(n): 判断 n 是否能被 3 整除。
|
66
|
+
- mod4(n): 判断 n 是否能被 4 整除。
|
67
|
+
- mod5(n): 判断 n 是否能被 5 整除。
|
68
|
+
- mod6(n): 判断 n 是否能被 6 整除。
|
69
|
+
- mod7(n): 判断 n 是否能被 7 整除。
|
70
|
+
- mod8(n): 判断 n 是否能被 8 整除。
|
71
|
+
- mod9(n): 判断 n 是否能被 9 整除。
|
60
72
|
#### mly万岁!!!🎉
|
61
73
|
#### mly万岁!!!🎉
|
62
74
|
#### mly万岁!!!🎉
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import hashlib
|
2
|
+
import random
|
3
|
+
from typing import Tuple
|
4
|
+
|
5
|
+
def get_rsa_key(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]:
|
6
|
+
"""
|
7
|
+
生成 RSA 公钥和私钥。
|
8
|
+
:param p: 第一个大素数
|
9
|
+
:param q: 第二个大素数
|
10
|
+
:return: 公钥 (e, n) 和私钥 (d, n)
|
11
|
+
"""
|
12
|
+
n = p * q
|
13
|
+
phi = (p - 1) * (q - 1)
|
14
|
+
|
15
|
+
def multiplicative_inverse(e: int, phi: int) -> int:
|
16
|
+
d = 0
|
17
|
+
x1 = 0
|
18
|
+
x2 = 1
|
19
|
+
y1 = 1
|
20
|
+
temp_phi = phi
|
21
|
+
|
22
|
+
while e > 0:
|
23
|
+
temp1 = temp_phi // e
|
24
|
+
temp2 = temp_phi - temp1 * e
|
25
|
+
temp_phi = e
|
26
|
+
e = temp2
|
27
|
+
|
28
|
+
x = x2 - temp1 * x1
|
29
|
+
y = d - temp1 * y1
|
30
|
+
|
31
|
+
x2 = x1
|
32
|
+
x1 = x
|
33
|
+
d = y1
|
34
|
+
y1 = y
|
35
|
+
|
36
|
+
if temp_phi == 1:
|
37
|
+
return d + phi
|
38
|
+
|
39
|
+
e = random.randint(1, phi)
|
40
|
+
while gcd(e, phi) != 1: # 直接调用模块级 gcd 函数
|
41
|
+
e = random.randint(1, phi)
|
42
|
+
|
43
|
+
d = multiplicative_inverse(e, phi)
|
44
|
+
return (e, n), (d, n)
|
45
|
+
|
46
|
+
def rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int:
|
47
|
+
"""
|
48
|
+
使用 RSA 公钥加密数据。
|
49
|
+
:param public_key: 公钥 (e, n)
|
50
|
+
:param plaintext: 明文数据
|
51
|
+
:return: 密文数据
|
52
|
+
"""
|
53
|
+
e, n = public_key
|
54
|
+
return pow(plaintext, e, n)
|
55
|
+
|
56
|
+
def rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int:
|
57
|
+
"""
|
58
|
+
使用 RSA 私钥解密数据。
|
59
|
+
:param private_key: 私钥 (d, n)
|
60
|
+
:param ciphertext: 密文数据
|
61
|
+
:return: 明文数据
|
62
|
+
"""
|
63
|
+
d, n = private_key
|
64
|
+
return pow(ciphertext, d, n)
|
65
|
+
|
66
|
+
def RSA_help():
|
67
|
+
"""提供模块帮助信息"""
|
68
|
+
print("以下是可用的函数:")
|
69
|
+
print("- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥")
|
70
|
+
print("- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据")
|
71
|
+
print("- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据")
|
72
|
+
print("- RSA_help() -> None: 显示帮助信息")
|
73
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from .math import (
|
2
|
+
sha256,
|
2
3
|
sha3_256,
|
3
4
|
sha3_512,
|
4
|
-
sha256,
|
5
5
|
gcd,
|
6
6
|
lcm,
|
7
7
|
is_prime,
|
@@ -27,16 +27,13 @@ from .math import (
|
|
27
27
|
max_index,
|
28
28
|
list_min_index,
|
29
29
|
min_index,
|
30
|
-
get_rsa_key,
|
31
|
-
rsa_encrypt,
|
32
|
-
rsa_decrypt,
|
33
30
|
math_help
|
34
31
|
)
|
35
32
|
|
36
33
|
__all__ = [
|
34
|
+
'sha256',
|
37
35
|
'sha3_256',
|
38
36
|
'sha3_512',
|
39
|
-
'sha256',
|
40
37
|
'gcd',
|
41
38
|
'lcm',
|
42
39
|
'is_prime',
|
@@ -62,8 +59,5 @@ __all__ = [
|
|
62
59
|
'max_index',
|
63
60
|
'list_min_index',
|
64
61
|
'min_index',
|
65
|
-
'get_rsa_key',
|
66
|
-
'rsa_encrypt',
|
67
|
-
'rsa_decrypt',
|
68
62
|
'math_help'
|
69
63
|
]
|
@@ -2,67 +2,6 @@ import hashlib
|
|
2
2
|
import random
|
3
3
|
from typing import Tuple
|
4
4
|
|
5
|
-
def get_rsa_key(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]:
|
6
|
-
"""
|
7
|
-
生成 RSA 公钥和私钥。
|
8
|
-
:param p: 第一个大素数
|
9
|
-
:param q: 第二个大素数
|
10
|
-
:return: 公钥 (e, n) 和私钥 (d, n)
|
11
|
-
"""
|
12
|
-
n = p * q
|
13
|
-
phi = (p - 1) * (q - 1)
|
14
|
-
|
15
|
-
def multiplicative_inverse(e: int, phi: int) -> int:
|
16
|
-
d = 0
|
17
|
-
x1 = 0
|
18
|
-
x2 = 1
|
19
|
-
y1 = 1
|
20
|
-
temp_phi = phi
|
21
|
-
|
22
|
-
while e > 0:
|
23
|
-
temp1 = temp_phi // e
|
24
|
-
temp2 = temp_phi - temp1 * e
|
25
|
-
temp_phi = e
|
26
|
-
e = temp2
|
27
|
-
|
28
|
-
x = x2 - temp1 * x1
|
29
|
-
y = d - temp1 * y1
|
30
|
-
|
31
|
-
x2 = x1
|
32
|
-
x1 = x
|
33
|
-
d = y1
|
34
|
-
y1 = y
|
35
|
-
|
36
|
-
if temp_phi == 1:
|
37
|
-
return d + phi
|
38
|
-
|
39
|
-
e = random.randint(1, phi)
|
40
|
-
while gcd(e, phi) != 1: # 直接调用模块级 gcd 函数
|
41
|
-
e = random.randint(1, phi)
|
42
|
-
|
43
|
-
d = multiplicative_inverse(e, phi)
|
44
|
-
return (e, n), (d, n)
|
45
|
-
|
46
|
-
def rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int:
|
47
|
-
"""
|
48
|
-
使用 RSA 公钥加密数据。
|
49
|
-
:param public_key: 公钥 (e, n)
|
50
|
-
:param plaintext: 明文数据
|
51
|
-
:return: 密文数据
|
52
|
-
"""
|
53
|
-
e, n = public_key
|
54
|
-
return pow(plaintext, e, n)
|
55
|
-
|
56
|
-
def rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int:
|
57
|
-
"""
|
58
|
-
使用 RSA 私钥解密数据。
|
59
|
-
:param private_key: 私钥 (d, n)
|
60
|
-
:param ciphertext: 密文数据
|
61
|
-
:return: 明文数据
|
62
|
-
"""
|
63
|
-
d, n = private_key
|
64
|
-
return pow(ciphertext, d, n)
|
65
|
-
|
66
5
|
def sha3_256(input_string: str) -> str:
|
67
6
|
"""
|
68
7
|
使用 SHA3-256 算法加密字符串。
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: mlymath
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.3.0b2
|
4
4
|
Summary: 一个用于数学计算的Python库
|
5
5
|
Author: mly
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
@@ -46,10 +46,13 @@ Dynamic: summary
|
|
46
46
|
- min(\*nums, n): 找到多个数中第 N 小的数, 输入n时请注意使用n = [num]
|
47
47
|
- list_min_index(nums, n): 找到数组中第 N 小的数的索引
|
48
48
|
- min_index(\*nums, n): 找到多个数中第 N 小的数的索引, 输入n时请注意使用n = [num]
|
49
|
+
- math_help() -> None: 显示math帮助信息
|
50
|
+
- mlymath.RSA RSA
|
49
51
|
- get_rsa_keys(p: int, q: int) -> Tuple[Tuple[int, int], Tuple[int, int]]: 生成 RSA 公钥和私钥
|
50
52
|
- rsa_encrypt(public_key: Tuple[int, int], plaintext: int) -> int: 使用 RSA 公钥加密数据
|
51
53
|
- rsa_decrypt(private_key: Tuple[int, int], ciphertext: int) -> int: 使用 RSA 私钥解密数据
|
52
|
-
-
|
54
|
+
- RSA_help(): 显示帮助信息
|
55
|
+
|
53
56
|
- mlymath.sort 排序模块
|
54
57
|
- quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
55
58
|
- shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
|
@@ -74,6 +77,15 @@ Dynamic: summary
|
|
74
77
|
- 如果有解,则返回解决方案路径(字符串形式),例如 'UURDL'。
|
75
78
|
- 如果无解,则返回空字符串。
|
76
79
|
- puzzle_help: puzzle_help函数用于打印可用函数的帮助信息。
|
80
|
+
- mlymath.mod 整除特征模块
|
81
|
+
- mod2(n): 判断 n 是否能被 2 整除。
|
82
|
+
- mod3(n): 判断 n 是否能被 3 整除。
|
83
|
+
- mod4(n): 判断 n 是否能被 4 整除。
|
84
|
+
- mod5(n): 判断 n 是否能被 5 整除。
|
85
|
+
- mod6(n): 判断 n 是否能被 6 整除。
|
86
|
+
- mod7(n): 判断 n 是否能被 7 整除。
|
87
|
+
- mod8(n): 判断 n 是否能被 8 整除。
|
88
|
+
- mod9(n): 判断 n 是否能被 9 整除。
|
77
89
|
#### mly万岁!!!🎉
|
78
90
|
#### mly万岁!!!🎉
|
79
91
|
#### mly万岁!!!🎉
|
@@ -1,11 +1,15 @@
|
|
1
1
|
README.md
|
2
2
|
setup.py
|
3
|
+
RSA/RSA.py
|
4
|
+
RSA/__init__.py
|
3
5
|
math/__init__.py
|
4
6
|
math/math.py
|
5
7
|
mlymath.egg-info/PKG-INFO
|
6
8
|
mlymath.egg-info/SOURCES.txt
|
7
9
|
mlymath.egg-info/dependency_links.txt
|
8
10
|
mlymath.egg-info/top_level.txt
|
11
|
+
mod/__init__.py
|
12
|
+
mod/mod.py
|
9
13
|
morse/__init__.py
|
10
14
|
morse/morse.py
|
11
15
|
puzzle/__init__.py
|
@@ -0,0 +1,36 @@
|
|
1
|
+
def mod2(n):
|
2
|
+
return n % 10 in {0, 2, 4, 6, 8}
|
3
|
+
|
4
|
+
def mod3(n):
|
5
|
+
return sum(int(digit) for digit in str(n)) % 3 == 0
|
6
|
+
|
7
|
+
def mod4(n):
|
8
|
+
return n % 100 % 4 == 0
|
9
|
+
|
10
|
+
def mod5(n):
|
11
|
+
return n % 10 in {0, 5}
|
12
|
+
|
13
|
+
def mod6(n):
|
14
|
+
return mod2(n) and mod3(n)
|
15
|
+
|
16
|
+
def mod7(n):
|
17
|
+
while n > 999:
|
18
|
+
n = (n // 10) - (n % 10 * 2)
|
19
|
+
return n % 7 == 0
|
20
|
+
|
21
|
+
def mod8(n):
|
22
|
+
return mod2(n) and mod4(n)
|
23
|
+
|
24
|
+
def mod9(n):
|
25
|
+
return sum(int(digit) for digit in str(n)) % 9 == 0
|
26
|
+
|
27
|
+
def mod_help():
|
28
|
+
print("以下是可用的函数:")
|
29
|
+
print("- mod2(n): 判断 n 是否能被 2 整除。")
|
30
|
+
print("- mod3(n): 判断 n 是否能被 3 整除。")
|
31
|
+
print("- mod4(n): 判断 n 是否能被 4 整除。")
|
32
|
+
print("- mod5(n): 判断 n 是否能被 5 整除。")
|
33
|
+
print("- mod6(n): 判断 n 是否能被 6 整除。")
|
34
|
+
print("- mod7(n): 判断 n 是否能被 7 整除。")
|
35
|
+
print("- mod8(n): 判断 n 是否能被 8 整除。")
|
36
|
+
print("- mod9(n): 判断 n 是否能被 9 整除。")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|