pystringmath 1.0.0__py3-none-any.whl
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,298 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pystringmath
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Package for string maths
|
|
5
|
+
Home-page: https://github.com/shTrueDDel/pystringmath/
|
|
6
|
+
Author: shTrueDDel
|
|
7
|
+
Author-email: xeosscript@gmail.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/shTrueDDel/pystringmath/blob/main/README.MD
|
|
9
|
+
Keywords: math string mathstring crypto cryptography encoding decoding
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: keywords
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: project-url
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# String Arithmetic Library
|
|
29
|
+
|
|
30
|
+
*This documentation was translated and compiled with the help of AI. Examples may contain minor errors that do not affect the understanding of how it works.*
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
The library provides tools for performing arithmetic operations on strings by converting characters to their numeric codes (ASCII/Unicode) and back. It allows adding, subtracting, multiplying, and dividing strings with both numbers and other strings.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Class `to`
|
|
38
|
+
A helper class for converting strings to code arrays and back.
|
|
39
|
+
|
|
40
|
+
### Methods
|
|
41
|
+
|
|
42
|
+
#### `to.array(data)`
|
|
43
|
+
Converts a string to an array of character numeric codes.
|
|
44
|
+
|
|
45
|
+
**Parameters:**
|
|
46
|
+
- `data` (str) - input string
|
|
47
|
+
|
|
48
|
+
**Returns:**
|
|
49
|
+
- list[int] - array of character codes
|
|
50
|
+
|
|
51
|
+
**Exceptions:**
|
|
52
|
+
- `TypeError` - if input data is not a string
|
|
53
|
+
|
|
54
|
+
**Example:**
|
|
55
|
+
```python
|
|
56
|
+
>>> to.array('Hello')
|
|
57
|
+
[72, 101, 108, 108, 111]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
#### `to.chars(data)`
|
|
63
|
+
Converts an array of numeric codes back to a string.
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
- `data` (list[int]) - array of character codes
|
|
67
|
+
|
|
68
|
+
**Returns:**
|
|
69
|
+
- str - resulting string
|
|
70
|
+
|
|
71
|
+
**Exceptions:**
|
|
72
|
+
- `TypeError` - if input data is invalid
|
|
73
|
+
|
|
74
|
+
**Example:**
|
|
75
|
+
```python
|
|
76
|
+
>>> to.chars([72, 101, 108, 108, 111])
|
|
77
|
+
'Hello'
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Class `nmath`
|
|
83
|
+
Performs arithmetic operations on a string using a single number.
|
|
84
|
+
|
|
85
|
+
### General Features
|
|
86
|
+
- All methods accept a string and a number
|
|
87
|
+
- Operations are applied to each character in the string
|
|
88
|
+
- Result is returned as a string
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
#### `nmath.sum(data, plus)`
|
|
93
|
+
Adds a number to each character in the string.
|
|
94
|
+
|
|
95
|
+
**Parameters:**
|
|
96
|
+
- `data` (str) - source string
|
|
97
|
+
- `plus` (int) - number to add
|
|
98
|
+
|
|
99
|
+
**Returns:**
|
|
100
|
+
- str - new string
|
|
101
|
+
|
|
102
|
+
**Example:**
|
|
103
|
+
```python
|
|
104
|
+
>>> nmath.sum('ABC', 1)
|
|
105
|
+
'BCD' # A(65)+1=66('B'), B(66)+1=67('C'), C(67)+1=68('D')
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
#### `nmath.min(data, minus)`
|
|
111
|
+
Subtracts a number from each character in the string.
|
|
112
|
+
|
|
113
|
+
**Parameters:**
|
|
114
|
+
- `data` (str) - source string
|
|
115
|
+
- `minus` (int) - number to subtract
|
|
116
|
+
|
|
117
|
+
**Returns:**
|
|
118
|
+
- str - new string
|
|
119
|
+
|
|
120
|
+
**Example:**
|
|
121
|
+
```python
|
|
122
|
+
>>> nmath.min('DEF', 1)
|
|
123
|
+
'CDE' # D(68)-1=67('C'), E(69)-1=68('D'), F(70)-1=69('E')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
#### `nmath.mul(data, multiplier)`
|
|
129
|
+
Multiplies each character's code by a number.
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `data` (str) - source string
|
|
133
|
+
- `multiplier` (int) - multiplier
|
|
134
|
+
|
|
135
|
+
**Returns:**
|
|
136
|
+
- str - new string
|
|
137
|
+
|
|
138
|
+
**Example:**
|
|
139
|
+
```python
|
|
140
|
+
>>> nmath.mul('AB', 2)
|
|
141
|
+
'ÆÊ' # A(65)*2=130('Æ'), B(66)*2=132('Ê')
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
#### `nmath.div(data, divisor)`
|
|
147
|
+
Performs integer division of each character's code by a number.
|
|
148
|
+
|
|
149
|
+
**Parameters:**
|
|
150
|
+
- `data` (str) - source string
|
|
151
|
+
- `divisor` (int) - divisor
|
|
152
|
+
|
|
153
|
+
**Returns:**
|
|
154
|
+
- str - new string
|
|
155
|
+
|
|
156
|
+
**Exceptions:**
|
|
157
|
+
- `ZeroDivisionError` - when attempting division by zero
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
```python
|
|
161
|
+
>>> nmath.div('d', 2)
|
|
162
|
+
'2' # d(100)//2 = 50('2')
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Class `armath`
|
|
168
|
+
Performs element-wise arithmetic operations between two strings with cyclic repetition.
|
|
169
|
+
|
|
170
|
+
### General Features
|
|
171
|
+
- Accepts two strings
|
|
172
|
+
- Operations are performed on corresponding character codes
|
|
173
|
+
- If the second string is shorter, it's cyclically repeated (via `itertools.cycle`)
|
|
174
|
+
- Result is returned as a string
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
#### `armath.sum(data, plus)`
|
|
179
|
+
Element-wise addition of character codes from two strings.
|
|
180
|
+
|
|
181
|
+
**Parameters:**
|
|
182
|
+
- `data` (str) - first string
|
|
183
|
+
- `plus` (str) - second string (addend)
|
|
184
|
+
|
|
185
|
+
**Returns:**
|
|
186
|
+
- str - resulting string
|
|
187
|
+
|
|
188
|
+
**Example:**
|
|
189
|
+
```python
|
|
190
|
+
>>> armath.sum('ABC', '12')
|
|
191
|
+
'rtt' # A(65)+'1'(49)=114('r')
|
|
192
|
+
# B(66)+'2'(50)=116('t')
|
|
193
|
+
# C(67)+'1'(49)=116('t') - cyclic repetition of '12'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
#### `armath.min(data, subtrahend)`
|
|
199
|
+
Element-wise subtraction of second string character codes from the first.
|
|
200
|
+
|
|
201
|
+
**Parameters:**
|
|
202
|
+
- `data` (str) - first string
|
|
203
|
+
- `subtrahend` (str) - second string (subtrahend)
|
|
204
|
+
|
|
205
|
+
**Returns:**
|
|
206
|
+
- str - resulting string
|
|
207
|
+
|
|
208
|
+
**Example:**
|
|
209
|
+
```python
|
|
210
|
+
>>> armath.min('ABC', '12')
|
|
211
|
+
'\x10\x11\x12' # A(65)-'1'(49)=16 (DLE character, non-printable)
|
|
212
|
+
# Results may be in non-printable range
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
#### `armath.mul(data, multiplier)`
|
|
218
|
+
Element-wise multiplication of character codes from two strings.
|
|
219
|
+
|
|
220
|
+
**Parameters:**
|
|
221
|
+
- `data` (str) - first string
|
|
222
|
+
- `multiplier` (str) - second string (multipliers)
|
|
223
|
+
|
|
224
|
+
**Returns:**
|
|
225
|
+
- str - resulting string
|
|
226
|
+
|
|
227
|
+
**Example:**
|
|
228
|
+
```python
|
|
229
|
+
>>> armath.mul('AB', '12')
|
|
230
|
+
'1¡' # A(65)*'1'(49)=3185 - may exceed ASCII range
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
#### `armath.div(data, divisor)`
|
|
236
|
+
Element-wise integer division of first string character codes by second string codes.
|
|
237
|
+
|
|
238
|
+
**Parameters:**
|
|
239
|
+
- `data` (str) - first string (dividend)
|
|
240
|
+
- `divisor` (str) - second string (divisor)
|
|
241
|
+
|
|
242
|
+
**Returns:**
|
|
243
|
+
- str - resulting string
|
|
244
|
+
|
|
245
|
+
**Exceptions:**
|
|
246
|
+
- `ZeroDivisionError` - if the second string contains a character with code 0
|
|
247
|
+
|
|
248
|
+
**Example:**
|
|
249
|
+
```python
|
|
250
|
+
>>> armath.div('abcd', '12')
|
|
251
|
+
'\x00\x00\x00\x00' # Results may be non-printable
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Usage Examples
|
|
257
|
+
|
|
258
|
+
### Basic Operations
|
|
259
|
+
```python
|
|
260
|
+
# Simple numeric operations
|
|
261
|
+
text = "Hello"
|
|
262
|
+
encoded = nmath.sum(text, 5) # "Mjqqt" (shift by 5)
|
|
263
|
+
decoded = nmath.min(encoded, 5) # "Hello"
|
|
264
|
+
|
|
265
|
+
# String operations
|
|
266
|
+
result = armath.sum("Hello", "123") # Element-wise addition with cyclic repetition of "123"
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Encryption/Decryption
|
|
270
|
+
```python
|
|
271
|
+
# Simple shift cipher
|
|
272
|
+
def encrypt(text, key):
|
|
273
|
+
return nmath.sum(text, key)
|
|
274
|
+
|
|
275
|
+
def decrypt(text, key):
|
|
276
|
+
return nmath.min(text, key)
|
|
277
|
+
|
|
278
|
+
message = "Secret message"
|
|
279
|
+
encrypted = encrypt(message, 10)
|
|
280
|
+
decrypted = decrypt(encrypted, 10)
|
|
281
|
+
print(decrypted) # "Secret message"
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Variant Generation
|
|
285
|
+
```python
|
|
286
|
+
base = "Test"
|
|
287
|
+
variants = [nmath.mul(base, i) for i in range(1, 6)]
|
|
288
|
+
for i, variant in enumerate(variants, 1):
|
|
289
|
+
print(f"Variant {i}: {variant}")
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Notes and Limitations
|
|
295
|
+
|
|
296
|
+
1. **Encoding**: Works with Unicode characters, but results may be non-printable
|
|
297
|
+
2. **Integer Division**: Uses `//`, so fractional results are truncated
|
|
298
|
+
3. **Value Range**: Operation results may fall outside the printable character range
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
pystringmath-1.0.0.dist-info/licenses/LICENSE,sha256=G69gIr9H83u39ykihIDjWt1guZohcFi99ULUvafS23M,1058
|
|
2
|
+
pystringmath-1.0.0.dist-info/METADATA,sha256=mBhMJGEjWeRRCTmluFyD4E_-3V8ZzFpOCwEuDgcTHKc,6916
|
|
3
|
+
pystringmath-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
4
|
+
pystringmath-1.0.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
+
pystringmath-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright (c) 2026 shTrueDDel
|
|
2
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
3
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
4
|
+
THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
5
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|