Skip to content

Fountain Code: Efficient Python Implementation of LT Codes

License

Notifications You must be signed in to change notification settings

Spriteware/lt-codes-python

Repository files navigation

Fountain Code: Efficient Python Implementation of LT Codes

This project is the implementation in Python of the iterative encoding and iterative decoding algorithms of the LT Codes, an error correction code based on the principles of Fountain Codes by Michael Luby. I have written a whole article on LT Codes and this snippet that you can find here : franpapers.com

The encoder and decoder are optimized to handle big transfers for files between 1MB to 1GB at high speed.

Installation

This implementation requires at least python 3.x. Some packages are not built-in. To install them with pip you can do:

$ pip install -r requirements.txt

Usage

An example describing how to use the implementation is in lt_codes.py, and you can use it to encode/decode a file on the fly (creates a file copy):

$ python lt_codes.py filename [-h] [-r REDUNDANCY] [--systematic] [--verbose] [--x86]

As an example, here is a basic test to ensure the integrity of the final file:

$ echo "Hello!" > test.txt
$ python lt_codes.py test.txt --systematic

A new file test-copy.txt should be created with the same content.

Content

  • core.py contains the Symbol class, constants and functions that are used in both encoding and decoding.
  • distributions.py contains the two functions that generate degrees based on the ideal soliton and robust soliton distributions
  • encoder.py contains the encoding algorithm
  • decoder.py contains the decoding algorithm
  • md5_checker.sh calls lt_codes.py and then compare the integrity of the original file with the newly created file. The integrity check is made with md5sum, add the ".exe" if you work on Window. Replace it by md5 -r if you work on Mac, or run brew install md5sha1sum.

Benchmarks

The time consumed by the encoding and decoding process is completely related to the size of the file to encode and the wanted redundancy. I have made some measure on an Intel i5 @ 2.30GHz with a 1.5 redundancy :

Size (MB) Blocks Symbols Encoding Decoding
Time (s) Speed (MB/s) Time (s) Speed (MB/s)
1 16 24 0.00 - 0.00 -
100 1600 2400 0.21 476.1 0.31 322.5
1200 19200 28800 3.86 310.8 39.82 30.1
2000 32000 48000 6.44 310.5 104.10 19.2
3600 57600 86400 23.14 155.5 426.36 8.4

Note: PACKET_SIZE is set to 65536 for theses tests. Lowering it will result in lower speeds but it might be necessary to send small files in many chunks.

References

M.Luby, "LT Codes", The 43rd Annual IEEE Symposium on Foundations of Computer Science, 2002.

License

MIT License Copyright (c) 2018 François Andrieux

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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. 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.

About

Fountain Code: Efficient Python Implementation of LT Codes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published