libcorrect 0.1.0__cp315-cp315-win_amd64.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.
Binary file
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: libcorrect
3
+ Version: 0.1.0
4
+ Summary: Forward Error Correction - bindings for libcorrect
5
+ Home-page: https://github.com/ilanschnell/correct
6
+ Author: Ilan Schnell
7
+ Author-email: ilanschnell@gmail.com
8
+ License: BSD
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: C
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/x-rst
24
+ License-File: LICENSE
25
+ License-File: libcorrect/LICENSE
26
+ Requires-Dist: bitarray>=3.4
27
+ Dynamic: author
28
+ Dynamic: author-email
29
+ Dynamic: classifier
30
+ Dynamic: description
31
+ Dynamic: description-content-type
32
+ Dynamic: home-page
33
+ Dynamic: license
34
+ Dynamic: license-file
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
38
+
39
+ correct
40
+ =======
41
+
42
+ ``correct`` provides Python bindings for the convolutional and Reed-Solomon
43
+ forward error correction algorithms from `libcorrect`_. Convolutional codes
44
+ use bitarrays for encoded data, while Reed-Solomon codes operate on bytes.
45
+
46
+ The package requires Python 3.9 or later and bitarray 3.4 or later.
47
+
48
+ Example
49
+ -------
50
+
51
+ Create a rate 1/2, order 7 convolutional code, encode a message, and decode it
52
+ again::
53
+
54
+ >>> import correct
55
+ >>> conv = correct.Convolutional(2, 7, (0o161, 0o127))
56
+ >>> encoded = conv.encode(b"Hello world!")
57
+ >>> encoded.endian
58
+ 'big'
59
+ >>> len(encoded)
60
+ 208
61
+ >>> for i in 97, 123, 198:
62
+ ... encoded.invert(i)
63
+ >>> conv.decode(encoded)
64
+ b'Hello world!'
65
+
66
+ ``encoded`` is a big-endian ``bitarray.bitarray`` and can be stored,
67
+ transmitted, or modified using the normal bitarray operations.
68
+
69
+ Installation
70
+ ------------
71
+
72
+ Install the package from PyPI::
73
+
74
+ python -m pip install libcorrect
75
+
76
+ The Python binding and the vendored libcorrect sources are distributed under
77
+ BSD licenses. See ``LICENSE`` and ``libcorrect/LICENSE`` for details.
78
+
79
+ .. _libcorrect: https://github.com/quiet/libcorrect
@@ -0,0 +1,8 @@
1
+ correct.cp315-win_amd64.pyd,sha256=xng_sPN1WM33ZVarRhzTtj7x1To6eT9nNtCN-hoX-WY,34304
2
+ test_correct.py,sha256=Xwb90cRyqbXzqLRzNglEHThE33n81cqcOAD11eudGXM,6167
3
+ libcorrect-0.1.0.dist-info/licenses/LICENSE,sha256=VGOYDaUwxO7ZeuoVZqQUTWJOsE9itONwojm127bsfWY,1547
4
+ libcorrect-0.1.0.dist-info/licenses/libcorrect/LICENSE,sha256=LKo8u4z3nhxkwPvSBU3uLShMoOJ3rrvLsOxCZcOMX7g,1498
5
+ libcorrect-0.1.0.dist-info/METADATA,sha256=u71vdPAl3sZXB-_4qqV8Wv9hBL__8SQUyPZpXtmFI4U,2454
6
+ libcorrect-0.1.0.dist-info/WHEEL,sha256=0gLwYZa0C2fhgCxWR2c8HahwUiopqonVCV0wVwEg6fE,101
7
+ libcorrect-0.1.0.dist-info/top_level.txt,sha256=K74B9YGKqC9x-pkUx2Jz10zaLpvXEywfoQXnkfmzOU4,21
8
+ libcorrect-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp315-cp315-win_amd64
5
+
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2026, Ilan Schnell
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
24
+ The views and conclusions contained in the software and documentation are those
25
+ of the authors and should not be interpreted as representing official policies,
26
+ either expressed or implied, of the (Python) correct project.
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2016, Brian Armstrong
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,2 @@
1
+ correct
2
+ test_correct
test_correct.py ADDED
@@ -0,0 +1,164 @@
1
+ import unittest
2
+ from array import array
3
+
4
+ from bitarray import bitarray
5
+
6
+ import correct
7
+
8
+
9
+ CONV_CODES = [
10
+ (2, 6, (0o73, 0o61)),
11
+ (2, 7, (0o161, 0o127)),
12
+ (2, 8, (0o225, 0o373)),
13
+ (2, 9, (0o767, 0o545)),
14
+ (3, 6, (0o53, 0o75, 0o47)),
15
+ (3, 7, (0o137, 0o153, 0o121)),
16
+ (3, 8, (0o333, 0o257, 0o351)),
17
+ (3, 9, (0o417, 0o627, 0o675)),
18
+ ]
19
+
20
+
21
+ class ConvolutionalTests(unittest.TestCase):
22
+
23
+ def test_roundtrip(self):
24
+ for inv_rate, order, polynomials in CONV_CODES:
25
+ conv = correct.Convolutional(inv_rate, order, polynomials)
26
+ for msg in (b'', b'a', b'Hello world!', bytes(range(256))):
27
+ encoded = conv.encode(msg)
28
+ self.assertIs(type(encoded), bitarray)
29
+ self.assertEqual(encoded.endian, 'big')
30
+ self.assertEqual(len(encoded) % inv_rate, 0)
31
+ self.assertEqual(conv.decode(encoded), msg)
32
+
33
+ def test_correct_error(self):
34
+ conv = correct.Convolutional(2, 7, (0o161, 0o127))
35
+ msg = b'convolutional code'
36
+ encoded = conv.encode(msg)
37
+ for i in (0, 1, len(encoded) // 2, len(encoded) - 1):
38
+ damaged = encoded.copy()
39
+ damaged.invert(i)
40
+ self.assertEqual(conv.decode(damaged), msg)
41
+
42
+ def test_soft_decoding(self):
43
+ for inv_rate, order, polynomials in CONV_CODES:
44
+ conv = correct.Convolutional(inv_rate, order, polynomials)
45
+ for msg in (b'', b'a', b'soft decisions'):
46
+ encoded = conv.encode(msg)
47
+ soft = bytearray(255 if bit else 0 for bit in encoded)
48
+ self.assertEqual(conv.decode_soft(soft), msg)
49
+
50
+ conv = correct.Convolutional(2, 7, (0o161, 0o127))
51
+ encoded = conv.encode(b'soft decisions')
52
+ soft = bytearray(255 if bit else 0 for bit in encoded)
53
+ soft[len(soft) // 2] = 128
54
+ self.assertEqual(conv.decode_soft(soft), b'soft decisions')
55
+
56
+ def test_buffers(self):
57
+ conv = correct.Convolutional(2, 7, (0o161, 0o127))
58
+ self.assertEqual(conv.decode(conv.encode(bytearray(b'abc'))), b'abc')
59
+ self.assertEqual(conv.decode(conv.encode(memoryview(b'abc'))), b'abc')
60
+
61
+ with self.assertRaises(TypeError):
62
+ conv.encode(array('H', [1, 2]))
63
+
64
+ def test_invalid_codeword(self):
65
+ conv = correct.Convolutional(2, 7, (0o161, 0o127))
66
+ encoded = conv.encode(b'abc')
67
+
68
+ with self.assertRaises(TypeError):
69
+ conv.decode(encoded.tobytes())
70
+
71
+ little = bitarray(encoded, endian='little')
72
+ with self.assertRaises(ValueError):
73
+ conv.decode(little)
74
+
75
+ del encoded[-1]
76
+ with self.assertRaises(ValueError):
77
+ conv.decode(encoded)
78
+ with self.assertRaises(ValueError):
79
+ conv.decode_soft(bytearray(len(encoded)))
80
+
81
+ def test_invalid_parameters(self):
82
+ for inv_rate in (0, 1):
83
+ with self.assertRaises(ValueError):
84
+ correct.Convolutional(inv_rate, 7, ())
85
+ for order in (0, 17):
86
+ with self.assertRaises(ValueError):
87
+ correct.Convolutional(2, order, (0o161, 0o127))
88
+ with self.assertRaises(ValueError):
89
+ correct.Convolutional(2, 7, (0o161,))
90
+ for polynomial in (-1, 1 << 16):
91
+ with self.assertRaises(OverflowError):
92
+ correct.Convolutional(2, 7, (polynomial, 0o127))
93
+ with self.assertRaises(TypeError):
94
+ correct.Convolutional(2, 7, ('x', 0o127))
95
+
96
+
97
+ class ReedSolomonTests(unittest.TestCase):
98
+
99
+ def setUp(self):
100
+ self.rs = correct.ReedSolomon(32)
101
+
102
+ def test_roundtrip(self):
103
+ for msg in (b'', b'a', b'Hello world!', bytes(range(223))):
104
+ encoded = self.rs.encode(msg)
105
+ self.assertIs(type(encoded), bytes)
106
+ self.assertEqual(len(encoded), len(msg) + 32)
107
+ self.assertEqual(encoded[:len(msg)], msg)
108
+ self.assertEqual(self.rs.decode(encoded), msg)
109
+
110
+ def test_correct_errors(self):
111
+ msg = bytes(range(223))
112
+ encoded = self.rs.encode(msg)
113
+ for count in (1, 8, 16):
114
+ damaged = bytearray(encoded)
115
+ for i in range(count):
116
+ damaged[7 * i] ^= 0xff
117
+ self.assertEqual(self.rs.decode(damaged), msg)
118
+
119
+ def test_erasures(self):
120
+ msg = bytes(range(100))
121
+ damaged = bytearray(self.rs.encode(msg))
122
+ erasures = list(range(20))
123
+ for i in erasures:
124
+ damaged[i] ^= 0xff
125
+ self.assertEqual(self.rs.decode(damaged, erasures), msg)
126
+ self.assertEqual(self.rs.decode(damaged, erasures=erasures), msg)
127
+
128
+ def test_buffers(self):
129
+ encoded = self.rs.encode(bytearray(b'abc'))
130
+ self.assertEqual(self.rs.decode(memoryview(encoded)), b'abc')
131
+ with self.assertRaises(TypeError):
132
+ self.rs.encode(array('H', [1, 2]))
133
+
134
+ def test_invalid_blocks(self):
135
+ with self.assertRaises(ValueError):
136
+ self.rs.encode(bytes(224))
137
+ with self.assertRaises(ValueError):
138
+ self.rs.decode(bytes(31))
139
+ with self.assertRaises(ValueError):
140
+ self.rs.decode(bytes(256))
141
+
142
+ encoded = self.rs.encode(b'abc')
143
+ with self.assertRaises(ValueError):
144
+ self.rs.decode(encoded, range(33))
145
+ for pos in (-1, len(encoded)):
146
+ with self.assertRaises(ValueError):
147
+ self.rs.decode(encoded, [pos])
148
+ with self.assertRaises(TypeError):
149
+ self.rs.decode(encoded, ['x'])
150
+
151
+ def test_invalid_parameters(self):
152
+ for num_roots in (0, 255):
153
+ with self.assertRaises(ValueError):
154
+ correct.ReedSolomon(num_roots)
155
+ with self.assertRaises(OverflowError):
156
+ correct.ReedSolomon(32, primitive_polynomial=1 << 16)
157
+ with self.assertRaises(OverflowError):
158
+ correct.ReedSolomon(32, first_root=256)
159
+ with self.assertRaises(OverflowError):
160
+ correct.ReedSolomon(32, root_gap=256)
161
+
162
+
163
+ if __name__ == '__main__':
164
+ unittest.main()