TgCryptos 0.0.12__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.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: tgcryptos
3
+ Version: 0.0.12
4
+ Summary: Fast and Portable Cryptography Extension Library for Pyrofork
5
+ Home-page: https://github.com/Clinton-Abraham
6
+ Author: Clinton-Abraham
7
+ Author-email: clintonabrahamc@gmail.com
8
+ Project-URL: Source, https://github.com/Clinton-Abraham
9
+ Project-URL: Community, https://telegram.me/sources_codes
10
+ Project-URL: Documentation, https://telegram.me/Clinton_Abraham
11
+ Keywords: pyrogram pyrofork telegram
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: keywords
26
+ Dynamic: project-url
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ <p align="center">
31
+ 📦 <a href="https://pypi.org/project/TgCryptos/" style="text-decoration:none;">Tgcrypto</a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="https://telegram.me/Space_x_bots"><img src="https://img.shields.io/badge/Sᴘᴀᴄᴇ 𝕩 ʙᴏᴛꜱ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
36
+ <a href="https://telegram.me/clinton_abraham"><img src="https://img.shields.io/badge/Cʟɪɴᴛᴏɴ Aʙʀᴀʜᴀᴍ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
37
+ <a href="https://telegram.me/sources_codes"><img src="https://img.shields.io/badge/Sᴏᴜʀᴄᴇ ᴄᴏᴅᴇꜱ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
38
+ </p>
39
+
40
+ | Fast and Portable Cryptography Extension Library for Pyrofork |
41
+ |---------------------------------------------------------------|
42
+
43
+ TgCrypto is a cryptography library written in C as a python extension. It is designed to be portable, fast,
44
+ easy to install and use. TgCrypto is intended for [Pyrofork](https://github.com/Mayuri-Chan/pyrofork) and implements the
45
+ cryptographic algorithms telegram requires, namely
46
+
47
+
48
+ <details>
49
+ <summary>....</summary>
50
+
51
+ - **`AES-256-IGE`** - used in [MTProto v2.0](https://core.telegram.org/mtproto).
52
+ - **`AES-256-CTR`** - used for [CDN encrypted files](https://core.telegram.org/cdn).
53
+ - **`AES-256-CBC`** - used for [encrypted passport credentials](https://core.telegram.org/passport).
54
+
55
+ </details>
56
+
57
+ ## REQUIREMENTS
58
+
59
+ - Python 3.10 or higher.
60
+
61
+ ## INSTALLATION
62
+
63
+ ``` bash
64
+ $ pip3 install -U tgcryptos
65
+ ```
66
+
67
+ ## API
68
+
69
+ TgCrypto API consists of these six methods:
70
+
71
+ ```python
72
+ def ige256_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
73
+ def ige256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
74
+
75
+ def ctr256_encrypt(data: bytes, key: bytes, iv: bytes, state: bytes) -> bytes: ...
76
+ def ctr256_decrypt(data: bytes, key: bytes, iv: bytes, state: bytes) -> bytes: ...
77
+
78
+ def cbc256_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
79
+ def cbc256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
80
+ ```
81
+
82
+ ## USAGE
83
+
84
+ | IGE MODE |
85
+ |---------------------------------------------------------------|
86
+
87
+ <details>
88
+
89
+ Note : Data must be padded to match a multiple of the block size (16 bytes).
90
+
91
+ ``` python
92
+ import os
93
+ import tgcrypto
94
+
95
+ data = os.urandom(10 * 1024 * 1024 + 7) # 10 MB of random data + 7 bytes to show padding
96
+ key = os.urandom(32) # Random Key
97
+ iv = os.urandom(32) # Random IV
98
+
99
+ # Pad with zeroes: -7 % 16 = 9
100
+ data += bytes(-len(data) % 16)
101
+
102
+ ige_encrypted = tgcrypto.ige256_encrypt(data, key, iv)
103
+ ige_decrypted = tgcrypto.ige256_decrypt(ige_encrypted, key, iv)
104
+
105
+ print(data == ige_decrypted) # True
106
+ ```
107
+
108
+ </details>
109
+
110
+
111
+ | CBC MODE |
112
+ |---------------------------------------------------------------|
113
+
114
+ <details>
115
+
116
+ Note : Data must be padded to match a multiple of the block size (16 bytes).
117
+
118
+ ``` python
119
+ import os
120
+ import tgcrypto
121
+
122
+ data = os.urandom(10 * 1024 * 1024 + 7) # 10 MB of random data + 7 bytes to show padding
123
+ key = os.urandom(32) # Random Key
124
+
125
+ enc_iv = bytearray(os.urandom(16)) # Random IV
126
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
127
+
128
+ # Pad with zeroes: -7 % 16 = 9
129
+ data += bytes(-len(data) % 16)
130
+
131
+ cbc_encrypted = tgcrypto.cbc256_encrypt(data, key, enc_iv)
132
+ cbc_decrypted = tgcrypto.cbc256_decrypt(cbc_encrypted, key, dec_iv)
133
+
134
+ print(data == cbc_decrypted) # True
135
+ ```
136
+
137
+ </details>
138
+
139
+
140
+ | CTR MODE (stream) |
141
+ |---------------------------------------------------------------|
142
+
143
+ <details>
144
+
145
+ ``` python
146
+ import os
147
+ import tgcrypto
148
+ from io import BytesIO
149
+
150
+
151
+ data = BytesIO(os.urandom(10 * 1024 * 1024)) # 10 MB of random data
152
+
153
+ key = os.urandom(32) # Random Key
154
+
155
+ enc_iv = bytearray(os.urandom(16)) # Random IV
156
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
157
+
158
+ enc_state = bytes(1) # Encryption state, starts from 0
159
+ dec_state = bytes(1) # Decryption state, starts from 0
160
+
161
+ encrypted_data = BytesIO() # Encrypted data buffer
162
+ decrypted_data = BytesIO() # Decrypted data buffer
163
+
164
+ while True:
165
+ chunk = data.read(1024)
166
+
167
+ if not chunk:
168
+ break
169
+
170
+ # Write 1K encrypted bytes into the encrypted data buffer
171
+ encrypted_data.write(tgcrypto.ctr256_encrypt(chunk, key, enc_iv, enc_state))
172
+
173
+ # Reset position. We need to read it now
174
+ encrypted_data.seek(0)
175
+
176
+ while True:
177
+ chunk = encrypted_data.read(1024)
178
+
179
+ if not chunk:
180
+ break
181
+
182
+ # Write 1K decrypted bytes into the decrypted data buffer
183
+ decrypted_data.write(tgcrypto.ctr256_decrypt(chunk, key, dec_iv, dec_state))
184
+
185
+ print(data.getvalue() == decrypted_data.getvalue()) # True
186
+ ```
187
+ </details>
188
+
189
+
190
+ | CTR MODE (single chunk) |
191
+ |---------------------------------------------------------------|
192
+
193
+ <details>
194
+
195
+ ``` python
196
+ import os
197
+ import tgcrypto
198
+
199
+ data = os.urandom(10 * 1024 * 1024) # 10 MB of random data
200
+
201
+ key = os.urandom(32) # Random Key
202
+
203
+ enc_iv = bytearray(os.urandom(16)) # Random IV
204
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
205
+
206
+ ctr_encrypted = tgcrypto.ctr256_encrypt(data, key, enc_iv, bytes(1))
207
+ ctr_decrypted = tgcrypto.ctr256_decrypt(ctr_encrypted, key, dec_iv, bytes(1))
208
+
209
+ print(data == ctr_decrypted) # True
210
+ ```
211
+ </details>
212
+
213
+
214
+ ## License
215
+
216
+ [LGPLv3+](COPYING.lesser) © 2017 - 2024 [Dan](https://github.com/delivrance)
217
+ [LGPLv3+](COPYING.lesser) © 2025 - present [Clinton-Abraham](https://github.com/Clinton-Abraham)
@@ -0,0 +1,188 @@
1
+ <p align="center">
2
+ 📦 <a href="https://pypi.org/project/TgCryptos/" style="text-decoration:none;">Tgcrypto</a>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://telegram.me/Space_x_bots"><img src="https://img.shields.io/badge/Sᴘᴀᴄᴇ 𝕩 ʙᴏᴛꜱ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
7
+ <a href="https://telegram.me/clinton_abraham"><img src="https://img.shields.io/badge/Cʟɪɴᴛᴏɴ Aʙʀᴀʜᴀᴍ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
8
+ <a href="https://telegram.me/sources_codes"><img src="https://img.shields.io/badge/Sᴏᴜʀᴄᴇ ᴄᴏᴅᴇꜱ-30302f?style=flat&logo=telegram" alt="telegram badge"/></a>
9
+ </p>
10
+
11
+ | Fast and Portable Cryptography Extension Library for Pyrofork |
12
+ |---------------------------------------------------------------|
13
+
14
+ TgCrypto is a cryptography library written in C as a python extension. It is designed to be portable, fast,
15
+ easy to install and use. TgCrypto is intended for [Pyrofork](https://github.com/Mayuri-Chan/pyrofork) and implements the
16
+ cryptographic algorithms telegram requires, namely
17
+
18
+
19
+ <details>
20
+ <summary>....</summary>
21
+
22
+ - **`AES-256-IGE`** - used in [MTProto v2.0](https://core.telegram.org/mtproto).
23
+ - **`AES-256-CTR`** - used for [CDN encrypted files](https://core.telegram.org/cdn).
24
+ - **`AES-256-CBC`** - used for [encrypted passport credentials](https://core.telegram.org/passport).
25
+
26
+ </details>
27
+
28
+ ## REQUIREMENTS
29
+
30
+ - Python 3.10 or higher.
31
+
32
+ ## INSTALLATION
33
+
34
+ ``` bash
35
+ $ pip3 install -U tgcryptos
36
+ ```
37
+
38
+ ## API
39
+
40
+ TgCrypto API consists of these six methods:
41
+
42
+ ```python
43
+ def ige256_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
44
+ def ige256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
45
+
46
+ def ctr256_encrypt(data: bytes, key: bytes, iv: bytes, state: bytes) -> bytes: ...
47
+ def ctr256_decrypt(data: bytes, key: bytes, iv: bytes, state: bytes) -> bytes: ...
48
+
49
+ def cbc256_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
50
+ def cbc256_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes: ...
51
+ ```
52
+
53
+ ## USAGE
54
+
55
+ | IGE MODE |
56
+ |---------------------------------------------------------------|
57
+
58
+ <details>
59
+
60
+ Note : Data must be padded to match a multiple of the block size (16 bytes).
61
+
62
+ ``` python
63
+ import os
64
+ import tgcrypto
65
+
66
+ data = os.urandom(10 * 1024 * 1024 + 7) # 10 MB of random data + 7 bytes to show padding
67
+ key = os.urandom(32) # Random Key
68
+ iv = os.urandom(32) # Random IV
69
+
70
+ # Pad with zeroes: -7 % 16 = 9
71
+ data += bytes(-len(data) % 16)
72
+
73
+ ige_encrypted = tgcrypto.ige256_encrypt(data, key, iv)
74
+ ige_decrypted = tgcrypto.ige256_decrypt(ige_encrypted, key, iv)
75
+
76
+ print(data == ige_decrypted) # True
77
+ ```
78
+
79
+ </details>
80
+
81
+
82
+ | CBC MODE |
83
+ |---------------------------------------------------------------|
84
+
85
+ <details>
86
+
87
+ Note : Data must be padded to match a multiple of the block size (16 bytes).
88
+
89
+ ``` python
90
+ import os
91
+ import tgcrypto
92
+
93
+ data = os.urandom(10 * 1024 * 1024 + 7) # 10 MB of random data + 7 bytes to show padding
94
+ key = os.urandom(32) # Random Key
95
+
96
+ enc_iv = bytearray(os.urandom(16)) # Random IV
97
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
98
+
99
+ # Pad with zeroes: -7 % 16 = 9
100
+ data += bytes(-len(data) % 16)
101
+
102
+ cbc_encrypted = tgcrypto.cbc256_encrypt(data, key, enc_iv)
103
+ cbc_decrypted = tgcrypto.cbc256_decrypt(cbc_encrypted, key, dec_iv)
104
+
105
+ print(data == cbc_decrypted) # True
106
+ ```
107
+
108
+ </details>
109
+
110
+
111
+ | CTR MODE (stream) |
112
+ |---------------------------------------------------------------|
113
+
114
+ <details>
115
+
116
+ ``` python
117
+ import os
118
+ import tgcrypto
119
+ from io import BytesIO
120
+
121
+
122
+ data = BytesIO(os.urandom(10 * 1024 * 1024)) # 10 MB of random data
123
+
124
+ key = os.urandom(32) # Random Key
125
+
126
+ enc_iv = bytearray(os.urandom(16)) # Random IV
127
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
128
+
129
+ enc_state = bytes(1) # Encryption state, starts from 0
130
+ dec_state = bytes(1) # Decryption state, starts from 0
131
+
132
+ encrypted_data = BytesIO() # Encrypted data buffer
133
+ decrypted_data = BytesIO() # Decrypted data buffer
134
+
135
+ while True:
136
+ chunk = data.read(1024)
137
+
138
+ if not chunk:
139
+ break
140
+
141
+ # Write 1K encrypted bytes into the encrypted data buffer
142
+ encrypted_data.write(tgcrypto.ctr256_encrypt(chunk, key, enc_iv, enc_state))
143
+
144
+ # Reset position. We need to read it now
145
+ encrypted_data.seek(0)
146
+
147
+ while True:
148
+ chunk = encrypted_data.read(1024)
149
+
150
+ if not chunk:
151
+ break
152
+
153
+ # Write 1K decrypted bytes into the decrypted data buffer
154
+ decrypted_data.write(tgcrypto.ctr256_decrypt(chunk, key, dec_iv, dec_state))
155
+
156
+ print(data.getvalue() == decrypted_data.getvalue()) # True
157
+ ```
158
+ </details>
159
+
160
+
161
+ | CTR MODE (single chunk) |
162
+ |---------------------------------------------------------------|
163
+
164
+ <details>
165
+
166
+ ``` python
167
+ import os
168
+ import tgcrypto
169
+
170
+ data = os.urandom(10 * 1024 * 1024) # 10 MB of random data
171
+
172
+ key = os.urandom(32) # Random Key
173
+
174
+ enc_iv = bytearray(os.urandom(16)) # Random IV
175
+ dec_iv = enc_iv.copy() # Keep a copy for decryption
176
+
177
+ ctr_encrypted = tgcrypto.ctr256_encrypt(data, key, enc_iv, bytes(1))
178
+ ctr_decrypted = tgcrypto.ctr256_decrypt(ctr_encrypted, key, dec_iv, bytes(1))
179
+
180
+ print(data == ctr_decrypted) # True
181
+ ```
182
+ </details>
183
+
184
+
185
+ ## License
186
+
187
+ [LGPLv3+](COPYING.lesser) © 2017 - 2024 [Dan](https://github.com/delivrance)
188
+ [LGPLv3+](COPYING.lesser) © 2025 - present [Clinton-Abraham](https://github.com/Clinton-Abraham)
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,50 @@
1
+ from setuptools import find_packages, Extension, setup
2
+
3
+ with open("README.md", encoding="utf-8") as f:
4
+ readmes = f.read()
5
+
6
+ DATA00 = False
7
+ DATA01 = {
8
+ "Source": "https://github.com/Clinton-Abraham",
9
+ "Community": "https://telegram.me/sources_codes",
10
+ "Documentation": "https://telegram.me/Clinton_Abraham"
11
+ }
12
+
13
+ DATA02 = [
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ ]
20
+
21
+ DATA04 = "Fast and Portable Cryptography Extension Library for Pyrofork"
22
+
23
+ DATA03 = Extension(
24
+ "tgcrypto",
25
+ sources=[
26
+ "tgcrypto/tgcrypto.c",
27
+ "tgcrypto/aes256.c",
28
+ "tgcrypto/ige256.c",
29
+ "tgcrypto/ctr256.c",
30
+ "tgcrypto/cbc256.c"
31
+ ]
32
+ )
33
+
34
+ setup(
35
+ name="tgcryptos",
36
+ version="0.0.12",
37
+ zip_safe=DATA00,
38
+ description=DATA04,
39
+ classifiers=DATA02,
40
+ project_urls=DATA01,
41
+ ext_modules=[DATA03],
42
+ packages=find_packages(),
43
+ author="Clinton-Abraham",
44
+ long_description=readmes,
45
+ python_requires=">=3.10",
46
+ keywords="pyrogram pyrofork telegram",
47
+ url="https://github.com/Clinton-Abraham",
48
+ author_email="clintonabrahamc@gmail.com",
49
+ long_description_content_type="text/markdown",
50
+ )