crYpt-pr 0.0.1__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.
crypt_pr-0.0.1/LICENSE ADDED
@@ -0,0 +1,47 @@
1
+ MIT License
2
+ Copyright (c) [2026] [meiyingm1y1]
3
+
4
+
5
+ Permission is hereby granted, free of charge, to any person obtAIning a copy
6
+
7
+
8
+ of this software and associated documentation files (the "Software"), to deal
9
+
10
+
11
+ in the Software without restriction, including without limitation the rights
12
+
13
+
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+
16
+
17
+ copies of the Software, and to permit persons to whom the Software is
18
+
19
+
20
+ furnished to do so, subject to the following conditions:
21
+
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+
25
+
26
+ copies or substantial portions of the Software.
27
+
28
+
29
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+
31
+
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+
34
+
35
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+
37
+
38
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+
40
+
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+
43
+
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+
46
+
47
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: crYpt_pr
3
+ Version: 0.0.1
4
+ Summary: some methods about classical code
5
+ Author-email: meiyingm1y1 <2653708110@qq.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # Encryption Algorithms Module
15
+
16
+ This directory contains implementations of several classic encryption algorithms. Below is a brief description of each file:
17
+
18
+ ## File Descriptions
19
+
20
+ ### `__init__.py`
21
+ - This file marks the current directory as a Python package.
22
+
23
+ ### `caesar.py`
24
+ - Implements the Caesar Cipher encryption algorithm.
25
+ - Caesar Cipher is a simple substitution cipher that encrypts text by shifting letters in the alphabet by a fixed number of steps.
26
+ - Functions:
27
+ Caesar_encode(plaintext: str, key: int) -> str: Encrypts the given plaintext using the specified key.
28
+ plaintext: The input string to be encrypted.
29
+ key: The number of positions to shift each letter.
30
+ - Caesar_decode(ciphertext: str) -> dict: Attempts to decrypt the ciphertext by trying all possible keys.
31
+ ciphertext: The encrypted string to be decrypted.
32
+
33
+ ### `Playfair.py`
34
+ - Implements the Playfair Cipher encryption algorithm.
35
+ - Playfair Cipher is an encryption method based on a letter matrix, commonly used to encrypt text.
36
+ - Functions:
37
+ Playfair_encode(Keyword: str, Plaintext: str) -> str: Encrypts the plaintext using the Playfair cipher.
38
+ Keyword: The encryption key used to generate the matrix.
39
+ Plaintext: The input string to be encrypted.
40
+
41
+ ### `Vigenere.py`
42
+ - Implements the Vigenère Cipher encryption algorithm.
43
+ - Vigenère Cipher is a polyalphabetic substitution cipher that uses a key to determine the shift for each letter.
44
+ - functions:
45
+ Vigenere_encode(Plaintext: str, m: int, keyword: str) -> str: Encrypts the plaintext using the Vigenère cipher.
46
+ Plaintext: The input string to be encrypted.
47
+ m: The length of the keyword.
48
+ keyword: The encryption key.
49
+ ## Usage
50
+
51
+ 1. Import the modules:
52
+ ```python
53
+ from crYpt import caesar, Playfair, Vigenere
54
+ ```
55
+
56
+ 2. Call the corresponding functions to encrypt or decrypt.
57
+
58
+ ## Notes
59
+ - Ensure that the input text and key meet the requirements of each algorithm.
60
+ - For detailed usage instructions, refer to the comments in each file.
@@ -0,0 +1,47 @@
1
+ # Encryption Algorithms Module
2
+
3
+ This directory contains implementations of several classic encryption algorithms. Below is a brief description of each file:
4
+
5
+ ## File Descriptions
6
+
7
+ ### `__init__.py`
8
+ - This file marks the current directory as a Python package.
9
+
10
+ ### `caesar.py`
11
+ - Implements the Caesar Cipher encryption algorithm.
12
+ - Caesar Cipher is a simple substitution cipher that encrypts text by shifting letters in the alphabet by a fixed number of steps.
13
+ - Functions:
14
+ Caesar_encode(plaintext: str, key: int) -> str: Encrypts the given plaintext using the specified key.
15
+ plaintext: The input string to be encrypted.
16
+ key: The number of positions to shift each letter.
17
+ - Caesar_decode(ciphertext: str) -> dict: Attempts to decrypt the ciphertext by trying all possible keys.
18
+ ciphertext: The encrypted string to be decrypted.
19
+
20
+ ### `Playfair.py`
21
+ - Implements the Playfair Cipher encryption algorithm.
22
+ - Playfair Cipher is an encryption method based on a letter matrix, commonly used to encrypt text.
23
+ - Functions:
24
+ Playfair_encode(Keyword: str, Plaintext: str) -> str: Encrypts the plaintext using the Playfair cipher.
25
+ Keyword: The encryption key used to generate the matrix.
26
+ Plaintext: The input string to be encrypted.
27
+
28
+ ### `Vigenere.py`
29
+ - Implements the Vigenère Cipher encryption algorithm.
30
+ - Vigenère Cipher is a polyalphabetic substitution cipher that uses a key to determine the shift for each letter.
31
+ - functions:
32
+ Vigenere_encode(Plaintext: str, m: int, keyword: str) -> str: Encrypts the plaintext using the Vigenère cipher.
33
+ Plaintext: The input string to be encrypted.
34
+ m: The length of the keyword.
35
+ keyword: The encryption key.
36
+ ## Usage
37
+
38
+ 1. Import the modules:
39
+ ```python
40
+ from crYpt import caesar, Playfair, Vigenere
41
+ ```
42
+
43
+ 2. Call the corresponding functions to encrypt or decrypt.
44
+
45
+ ## Notes
46
+ - Ensure that the input text and key meet the requirements of each algorithm.
47
+ - For detailed usage instructions, refer to the comments in each file.
@@ -0,0 +1,91 @@
1
+ # ''.join(a)意思是以''内的元素为分割符号,把a各种元素连接起来
2
+ def deal_with(Keyword):
3
+
4
+ if 'i' in Keyword and 'j' in Keyword:
5
+ Keyword = Keyword.replace('j','')
6
+ if 'j' in Keyword:
7
+ Keyword = Keyword.replace('j','i')
8
+ return Keyword
9
+
10
+ def extract(Keyword):
11
+
12
+ List =[]
13
+ for i in range(len(Keyword)):
14
+ if Keyword[i] not in List:
15
+ List.append(Keyword[i])
16
+ return List
17
+
18
+ def matrix_insert(List,matrix:list):
19
+
20
+ j=0
21
+ for i,j in zip(List,range(len(List))):
22
+ matrix[j // 5].append(i)
23
+ j=j+1
24
+ Str="abcdefghiklmnopqrstuvwxyz"
25
+ Str=list(Str)
26
+ for i in Str:
27
+ if i not in List:
28
+ matrix[j // 5].append(i)
29
+ j=j+1#自增不能忘
30
+ return matrix
31
+
32
+ def transform_dict(matrix):
33
+
34
+ Dict:dict={}
35
+ for i in range(5):
36
+ for j in range(5):
37
+ Dict[matrix[i][j]]=(i,j)
38
+ return Dict
39
+
40
+ def adjust(Plaintext):
41
+
42
+ i = 0
43
+ t = len(Plaintext)
44
+ if 'i' in Plaintext and 'j' in Plaintext:
45
+ Plaintext = Plaintext.replace('j',' ')
46
+ if 'j' in Plaintext:
47
+ Plaintext = Plaintext.replace('j','i')
48
+ while(i<t):
49
+ if(i+1<t and Plaintext[i] == Plaintext[i+1]):
50
+ f=''
51
+ List="abcdefghiklmnopqrstuvwxyz"
52
+ for f in List:
53
+ if f != Plaintext[i] and f != Plaintext[i+1]:
54
+ break
55
+ Plaintext.insert(i+1,f)
56
+ i+=2
57
+ t=len(Plaintext)
58
+ return Plaintext
59
+
60
+ def Playfair_encode(Keyword,Plaintext):
61
+
62
+ Keyword = deal_with(Keyword)#关键字处理
63
+ List = extract(Keyword)
64
+ matrix =[[] for i in range(5)]
65
+ matrix = matrix_insert(List,matrix)
66
+ Dict = transform_dict(matrix)#获取字符位置字典
67
+ Plaintext = adjust(Plaintext)#明文调整
68
+ Slice = [[Plaintext[i],Plaintext[i+1]] if i+1<len(Plaintext) else [Plaintext[i],'k'] \
69
+ for i in range(0,len(Plaintext),2)]#获取分组切片
70
+ for Tuple in Slice:
71
+ if Dict[Tuple[0]][0] != Dict[Tuple[1]][0] and Dict[Tuple[0]][1] != Dict[Tuple[1]][1] :
72
+ Slice[Slice.index(Tuple)] = \
73
+ (matrix[Dict[Tuple[0]][0]][Dict[Tuple[1]][1]],matrix[Dict[Tuple[1]][0]][Dict[Tuple[0]][1]])
74
+ elif Dict[Tuple[0]][1] == Dict[Tuple[1]][1]:
75
+ Slice[Slice.index(Tuple)] = \
76
+ (matrix[(Dict[Tuple[0]][0]+1)%5][Dict[Tuple[0]][1]],matrix[(Dict[Tuple[1]][0]+1)%5][Dict[Tuple[1]][1]])
77
+ else:
78
+ Slice[Slice.index(Tuple)] = \
79
+ (matrix[Dict[Tuple[0]][0]][(Dict[Tuple[0]][1]+1)%5],matrix[Dict[Tuple[1]][0]][(Dict[Tuple[1]][1]+1)%5])
80
+ ciphertext=""
81
+ for result in Slice:
82
+ ciphertext+=''.join(result)
83
+ return ciphertext.upper()
84
+
85
+ if __name__ == "__main__" :
86
+ keyword = "monarchy"
87
+ Plaintext = "wearediscoveredsaveyourself"
88
+ ciphertext = Playfair_encode(keyword,Plaintext)
89
+ print(ciphertext)
90
+
91
+
@@ -0,0 +1,27 @@
1
+ from string import ascii_uppercase,ascii_lowercase
2
+
3
+ def transmit(keyword):
4
+ List = list(keyword)
5
+ a=[]
6
+ for c in keyword:
7
+ if c in ascii_uppercase:
8
+ a.append((ascii_uppercase.index(c)-ascii_uppercase.index('A'))%26)
9
+ else:
10
+ a.append((ascii_lowercase.index(c)-ascii_lowercase.index('a'))%26)
11
+ return a
12
+
13
+ def Vigenere_encode(Plaintext,m,keyword):
14
+ keyword = transmit(keyword)
15
+ ciphertext = ""
16
+ for i in range(len(Plaintext)):
17
+ if Plaintext[i] in ascii_uppercase:
18
+ ciphertext += ascii_uppercase[(ascii_uppercase.index(Plaintext[i])+keyword[i%m])%26]
19
+ else :
20
+ ciphertext += ascii_lowercase[(ascii_lowercase.index(Plaintext[i])+keyword[i%m])%26]
21
+ return ciphertext
22
+
23
+ if __name__ == "__main__":
24
+ keyword = "vector"
25
+ Plaintext = "hereishowitworks"
26
+ ciphertext = Vigenere_encode(Plaintext,6,keyword)
27
+ print(ciphertext)
@@ -0,0 +1,5 @@
1
+ from .caesar import *
2
+ from .Playfair import *
3
+ from .Vigenere import *
4
+
5
+
@@ -0,0 +1,25 @@
1
+ #下面实现一下凯撒密码(Caesar Crypt)的加密与唯密文解密
2
+
3
+ def Caesar_encode(plaintext : str , key : int):
4
+ ciphertext=""
5
+ for s_chr in plaintext:
6
+ if (ord(s_chr)>=97 and ord(s_chr) <= 122):
7
+ ciphertext += chr((ord(s_chr)+key-ord('a'))%26+ord('a'))
8
+ elif (ord(s_chr)>=65 and ord(s_chr) <= 90):
9
+ ciphertext += chr((ord(s_chr)+key-ord('A'))%26+ord('A'))
10
+ else:
11
+ ciphertext += s_chr
12
+ return ciphertext
13
+ def Caesar_decode(ciphertext):
14
+ msg = {}
15
+ for key in range(1,26):
16
+ plaintext=""
17
+ for s_chr in ciphertext:
18
+ if (ord(s_chr) >= 97 and ord(s_chr) <=122):
19
+ plaintext += chr((ord(s_chr)-key-ord('a'))%26+ord('a'))
20
+ elif (ord(s_chr) >= 65 and ord(s_chr) <=90):
21
+ plaintext += chr((ord(s_chr)-key-ord('A'))%26+ord('A'))
22
+ else :
23
+ plaintext += s_chr
24
+ msg[key]=plaintext
25
+ return msg
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: crYpt_pr
3
+ Version: 0.0.1
4
+ Summary: some methods about classical code
5
+ Author-email: meiyingm1y1 <2653708110@qq.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # Encryption Algorithms Module
15
+
16
+ This directory contains implementations of several classic encryption algorithms. Below is a brief description of each file:
17
+
18
+ ## File Descriptions
19
+
20
+ ### `__init__.py`
21
+ - This file marks the current directory as a Python package.
22
+
23
+ ### `caesar.py`
24
+ - Implements the Caesar Cipher encryption algorithm.
25
+ - Caesar Cipher is a simple substitution cipher that encrypts text by shifting letters in the alphabet by a fixed number of steps.
26
+ - Functions:
27
+ Caesar_encode(plaintext: str, key: int) -> str: Encrypts the given plaintext using the specified key.
28
+ plaintext: The input string to be encrypted.
29
+ key: The number of positions to shift each letter.
30
+ - Caesar_decode(ciphertext: str) -> dict: Attempts to decrypt the ciphertext by trying all possible keys.
31
+ ciphertext: The encrypted string to be decrypted.
32
+
33
+ ### `Playfair.py`
34
+ - Implements the Playfair Cipher encryption algorithm.
35
+ - Playfair Cipher is an encryption method based on a letter matrix, commonly used to encrypt text.
36
+ - Functions:
37
+ Playfair_encode(Keyword: str, Plaintext: str) -> str: Encrypts the plaintext using the Playfair cipher.
38
+ Keyword: The encryption key used to generate the matrix.
39
+ Plaintext: The input string to be encrypted.
40
+
41
+ ### `Vigenere.py`
42
+ - Implements the Vigenère Cipher encryption algorithm.
43
+ - Vigenère Cipher is a polyalphabetic substitution cipher that uses a key to determine the shift for each letter.
44
+ - functions:
45
+ Vigenere_encode(Plaintext: str, m: int, keyword: str) -> str: Encrypts the plaintext using the Vigenère cipher.
46
+ Plaintext: The input string to be encrypted.
47
+ m: The length of the keyword.
48
+ keyword: The encryption key.
49
+ ## Usage
50
+
51
+ 1. Import the modules:
52
+ ```python
53
+ from crYpt import caesar, Playfair, Vigenere
54
+ ```
55
+
56
+ 2. Call the corresponding functions to encrypt or decrypt.
57
+
58
+ ## Notes
59
+ - Ensure that the input text and key meet the requirements of each algorithm.
60
+ - For detailed usage instructions, refer to the comments in each file.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ crYpt_pr/Playfair.py
5
+ crYpt_pr/Vigenere.py
6
+ crYpt_pr/__init__.py
7
+ crYpt_pr/caesar.py
8
+ crYpt_pr.egg-info/PKG-INFO
9
+ crYpt_pr.egg-info/SOURCES.txt
10
+ crYpt_pr.egg-info/dependency_links.txt
11
+ crYpt_pr.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ crYpt_pr
@@ -0,0 +1,16 @@
1
+ [project]
2
+ name = "crYpt_pr"
3
+ version = "0.0.1"
4
+ authors = [
5
+ { name="meiyingm1y1", email="2653708110@qq.com" },
6
+ ]
7
+ description = "some methods about classical code"
8
+ readme = "README.md"
9
+ requires-python = ">=3.9"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ license = "MIT"
15
+ license-files = ["LICEN[CS]E*"]
16
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+