Skip to main content

Pure-Python Reed Solomon encoder/decoder

Project description

A pure-python Reed Solomon encoder/decoder, based on the wonderful tutorial at wikiversity, written by “Bobmath”.

I only consolidated the code a little and added exceptions and a simple API. To my understanding, the algorithm can correct up to nsym/2 of the errors in the message, where nsym is the number of bytes in the error correction code. The code should work on pretty much any reasonable version of python (2.4-3.2), but I’m only testing on 2.6-3.2.

>>> rs = RSCodec(10)
>>> rs.encode([1,2,3,4])
'\x01\x02\x03\x04,\x9d\x1c+=\xf8h\xfa\x98M'
>>> rs.encode("hello world")
'hello world\xed%T\xc4\xfd\xfd\x89\xf3\xa8\xaa'
>>> rs.decode(b'hello world\xed%T\xc4\xfd\xfd\x89\xf3\xa8\xaa')
'hello world'
>>> rs.decode(b'hello worXd\xed%T\xc4\xfd\xfd\x89\xf3\xa8\xaa')  # 1 error
'hello world'
>>> rs.decode(b'heXlo worXd\xed%T\xc4\xfdX\x89\xf3\xa8\xaa')     # 3 errors
'hello world'
>>> rs.decode(b'hXXlo worXd\xed%T\xc4\xfdX\x89\xf3\xa8\xaa')     # 4 errors
'hello world'
>>> rs.decode(b'hXXXo worXd\xed%T\xc4\xfdX\x89\xf3\xa8\xaa')     # 5 errors
'hello world'
>>> rs.decode(b'hXXXo worXd\xed%T\xc4\xfdXX\xf3\xa8\xaa')        # 6 errors - fail
Traceback (most recent call last):
  ...
ReedSolomonError: Could not locate error

>>> rs = RSCodec(12)
>>> rs.encode("hello world")
'hello world?Ay\xb2\xbc\xdc\x01q\xb9\xe3\xe2='
>>> rs.decode(b'hello worXXXXy\xb2XX\x01q\xb9\xe3\xe2=')         # 6 errors - ok
'hello world'

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

reedsolo-0.1.zip (8.1 kB view details)

Uploaded Source

reedsolo-0.1.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file reedsolo-0.1.zip.

File metadata

  • Download URL: reedsolo-0.1.zip
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for reedsolo-0.1.zip
Algorithm Hash digest
SHA256 e7b21bf5ae156cb1941f99786d947632731e482a27c15400be9340736c10e1c4
MD5 fb1a12b49fe476877c27a85ccd40dbe2
BLAKE2b-256 1266c3680807e02ac92722d91e3c34e27b0411d183014e207a770a2f637e5967

See more details on using hashes here.

File details

Details for the file reedsolo-0.1.tar.gz.

File metadata

  • Download URL: reedsolo-0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for reedsolo-0.1.tar.gz
Algorithm Hash digest
SHA256 c32e9570d996e975cd8b02f4a1044517aba120b8ff7f74dcbf8d106e3a6ddeb2
MD5 12a842aed5a11d1c9712a179cd2e464b
BLAKE2b-256 c8199572e3e2604111c80b2ae79b4e9ff3967395d9d60fe9d5b5e55a649532f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page