├── reedmuller ├── __init__.py ├── rmencode.py ├── rmdecode.py └── reedmuller.py ├── setup.cfg ├── reed_muller.pdf ├── NOTES ├── .idea ├── misc.xml ├── vcs.xml ├── modules.xml ├── reedmuller.iml └── workspace.xml ├── README.md ├── LICENSE ├── .gitignore └── setup.py /reedmuller/__init__.py: -------------------------------------------------------------------------------- 1 | from . import reedmuller 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [egg_info] 2 | tag_build = 3 | tag_date = 0 4 | tag_svn_revision = 0 5 | 6 | -------------------------------------------------------------------------------- /reed_muller.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sraaphorst/reed-muller-python/HEAD/reed_muller.pdf -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | To build: 2 | python3 setup.py bdist_egg sdist 3 | 4 | To upload to pypi: 5 | twine upload --repository-url https://upload.pypi.org/legacy/ dist/* -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/reedmuller.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reed-Muller Codes in Python 2 | 3 | **Status:** Complete, verson 1.1.2. 4 | 5 | This is a research project I completed for a course at Carleton University, "Finite Fields and Coding Theory." 6 | 7 | This comprises a paper that attempts to present Reed-Muller codes in a simplistic way, and includes a Python implementation of 8 | encoding and decoding (using majority logic) using Reed-Muller codes. 9 | 10 | Code now works on both Python 2 and Python 3. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Sebastian Raaphorst 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | .gitignore_files 39 | .gitignore_files/* -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup 4 | 5 | with open("README.md", "r") as fh: 6 | long_description = fh.read() 7 | 8 | setup(name='reedmuller', 9 | version='1.1.2', 10 | description='Reed-Muller encoding and decoding', 11 | author='Sebastian Raaphorst', 12 | author_email='srcoding@gmail.com', 13 | url='https://github.com/sraaphorst/reedmuller', 14 | packages=['reedmuller'], 15 | long_description=long_description, 16 | long_description_content_type="text/markdown", 17 | classifiers=[ 18 | 'License :: OSI Approved :: Apache Software License', 19 | 'Programming Language :: Python', 20 | 'Development Status :: 4 - Beta', 21 | 'Intended Audience :: Developers', 22 | 'Topic :: Scientific/Engineering :: Mathematics', 23 | ], 24 | keywords='mathematics combinatorics codes reedmuller', 25 | license='Apache 2.0' 26 | ) 27 | -------------------------------------------------------------------------------- /reedmuller/rmencode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """rmencode.py 3 | 4 | By Sebastian Raaphorst, 2012. 5 | 6 | Simple command-line application for Reed-Muller encoding of one or more 0-1 strings.""" 7 | 8 | import sys 9 | import reedmuller 10 | 11 | if __name__ == '__main__': 12 | # Validate the command-line parameters. 13 | if len(sys.argv) < 4: 14 | sys.stderr.write('Usage: %s r m word [word [...]]\n' % (sys.argv[0],)) 15 | sys.exit(1) 16 | 17 | r, m = map(int, sys.argv[1:3]) 18 | if (m <= r): 19 | sys.stderr.write('We require r < m.\n') 20 | sys.exit(2) 21 | 22 | # Create the code. 23 | rm = reedmuller.ReedMuller(r, m) 24 | k = rm.message_length() 25 | 26 | # Now iterate over the words to encode, validate them, and encode them. 27 | for word in sys.argv[3:]: 28 | try: 29 | listword = list(map(int, word)) 30 | if (not set(listword).issubset([0, 1])) or (len(listword) != k): 31 | sys.stderr.write('FAIL: word %s is not a 0-1 string of length %d\n' % (word, k)) 32 | else: 33 | print(''.join(map(str, rm.encode(listword)))) 34 | except: 35 | sys.stderr.write('FAIL: word %s is not a 0-1 string of length %d\n' % (word, k)) 36 | -------------------------------------------------------------------------------- /reedmuller/rmdecode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """rmdecode.py 3 | 4 | By Sebastian Raaphorst, 2012. 5 | 6 | Simple command-line application for Reed-Muller decoding of one or more 0-1 strings.""" 7 | 8 | import sys 9 | import reedmuller 10 | 11 | if __name__ == '__main__': 12 | # Validate the command-line parameters. 13 | if len(sys.argv) < 4: 14 | sys.stderr.write('Usage: %s r m codeword [codeword [...]]\n' % (sys.argv[0],)) 15 | sys.exit(1) 16 | 17 | r, m = map(int, sys.argv[1:3]) 18 | if (m <= r): 19 | sys.stderr.write('We require r < m.\n') 20 | sys.exit(2) 21 | 22 | # Create the code. 23 | rm = reedmuller.ReedMuller(r, m) 24 | n = rm.block_length() 25 | 26 | # Now iterate over the words to encode, validate them, and encode them. 27 | for codeword in sys.argv[3:]: 28 | try: 29 | listword = list(map(int, codeword)) 30 | if (not set(listword).issubset([0, 1])) or (len(listword) != n): 31 | sys.stderr.write('FAIL: word %s is not a 0-1 string of length %d\n' % (codeword, n)) 32 | else: 33 | decodeword = rm.decode(listword) 34 | if not decodeword: 35 | print('Could not unambiguously decode word %s' % (codeword)) 36 | else: 37 | print(''.join(map(str, decodeword))) 38 | except: 39 | print("Unexpected error:", sys.exc_info()[0]) 40 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | zip 56 | 57 | 58 | range 59 | 60 | 61 | 62 | 64 | 65 | 72 | 73 | 74 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |