mlymath 0.3.0b1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mlymath
3
- Version: 0.3.0b1
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
- - math_help() -> None: 显示math帮助信息
54
+ - RSA_help(): 显示帮助信息
55
+
53
56
  - mlymath.sort 排序模块
54
57
  - quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
55
58
  - shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
@@ -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
- - math_help() -> None: 显示math帮助信息
37
+ - RSA_help(): 显示帮助信息
38
+
36
39
  - mlymath.sort 排序模块
37
40
  - quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
38
41
  - shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
@@ -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
+
@@ -0,0 +1,13 @@
1
+ from .RSA import (
2
+ get_rsa_key,
3
+ rsa_encrypt,
4
+ rsa_decrypt,
5
+ RSA_help
6
+ )
7
+
8
+ __all__ = [
9
+ 'get_rsa_key',
10
+ 'rsa_encrypt',
11
+ 'rsa_decrypt',
12
+ 'RSA_help'
13
+ ]
@@ -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.0b1
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
- - math_help() -> None: 显示math帮助信息
54
+ - RSA_help(): 显示帮助信息
55
+
53
56
  - mlymath.sort 排序模块
54
57
  - quick_sort: 使用快速排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
55
58
  - shell_sort: 使用希尔排序算法对数组进行排序。可通过 reverse 参数控制排序顺序(默认正序)
@@ -1,5 +1,7 @@
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
@@ -1,3 +1,4 @@
1
+ RSA
1
2
  math
2
3
  mod
3
4
  morse
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as fh:
5
5
 
6
6
  setup(
7
7
  name='mlymath',
8
- version='0.3.0-beta1',
8
+ version='0.3.0-beta2',
9
9
  packages=find_packages(),
10
10
  install_requires=[
11
11
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes