All Projects → jkent → python-bchlib

jkent / python-bchlib

Licence: GPL-2.0 license
BCH library C Python module

Programming Languages

c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to python-bchlib

transloadify
🤖☁️📽📦 Transloadit's cloud encoding in a box
Stars: ✭ 26 (-55.17%)
Mutual labels:  encoding
RLPSwift
Recursive Length Prefix encoding written in Swift
Stars: ✭ 22 (-62.07%)
Mutual labels:  encoding
wat
WAT - Windows ACME Tool
Stars: ✭ 28 (-51.72%)
Mutual labels:  ecc
ronin-support
A support library for Ronin. Like activesupport, but for hacking!
Stars: ✭ 23 (-60.34%)
Mutual labels:  encoding
carrot-pool-stratum
Bitcoin Stratum Pool Plugin ⛏ 📦 🔌
Stars: ✭ 22 (-62.07%)
Mutual labels:  bch
go-sdk
Transloadit's official Go SDK, maintained by the community
Stars: ✭ 17 (-70.69%)
Mutual labels:  encoding
codec
Encode keys, values and range options, with built-in or custom encodings.
Stars: ✭ 27 (-53.45%)
Mutual labels:  encoding
ffcvt
ffmpeg convert wrapper tool
Stars: ✭ 32 (-44.83%)
Mutual labels:  encoding
ParPar
High performance PAR2 create client for NodeJS
Stars: ✭ 110 (+89.66%)
Mutual labels:  ecc
galois
A performant NumPy extension for Galois fields and their applications
Stars: ✭ 106 (+82.76%)
Mutual labels:  bch
go-webp
Simple and fast webp library for golang
Stars: ✭ 91 (+56.9%)
Mutual labels:  encoding
ImHex-Patterns
Hex patterns, include patterns and magic files for the use with the ImHex Hex Editor
Stars: ✭ 192 (+231.03%)
Mutual labels:  encoding
DjvuNet
DjvuNet is a cross platform fully managed .NET library for working with Djvu documents which can run on Linux, macOS and Windows. Library has been written in C# and targets .NET Core v3.0 and .NET Standard v2.1 or later. We intend to provide DjVu document processing capabilities on par with DjVuLibre reference library (or even better).
Stars: ✭ 54 (-6.9%)
Mutual labels:  encoding
wave-gui
Yet another data-over-sound tool
Stars: ✭ 64 (+10.34%)
Mutual labels:  ecc
fast-text-encoding
Fast polyfill for TextEncoder and TextDecoder, only supports UTF-8
Stars: ✭ 78 (+34.48%)
Mutual labels:  encoding
BeFoR64
BeFoR64, Base64 encoding/decoding library for FoRtran poor men
Stars: ✭ 17 (-70.69%)
Mutual labels:  encoding
ffmpegd
FFmpeg websocket server for ffmpeg-commander.
Stars: ✭ 37 (-36.21%)
Mutual labels:  encoding
cryptouri.rs
Rust implementation of CryptoURI: URN-like namespace for cryptographic objects with Bech32-based encoding
Stars: ✭ 33 (-43.1%)
Mutual labels:  encoding
hazmat-math
Hazmat ECC arithmetic for Cryptography.io
Stars: ✭ 28 (-51.72%)
Mutual labels:  ecc
dvdisaster
A tool providing additional ECC protection for optical media (unofficial version)
Stars: ✭ 116 (+100%)
Mutual labels:  ecc

python-bchlib Build Status

This is a python module for encoding and correcting data using BCH codes.

Requirements

For Windows, python3.5 or greater required.
For Linux and MacOS, python2.7 or python3.4 or greater required.

Installing the latest release:

$ pip install bchlib

Installing from source:

Make sure you have python-dev setup. For Windows, this means you need Visual Studio 2015.

$ pip install .

Module Documentation

bchlib.BCH( polynomial, t[, reverse] ) → bch

Constructor creates a BCH object with given polynomial and t bit strength, reverse is an optional boolean that flips the bit order of data. The Galois field order is automatically determined from the polynomial.

bch.encode( data[, ecc] ) → ecc

Encodes data with an optional starting ecc and returns an ecc.

bch.decode( data, ecc ) → ( bitflips, data, ecc )

Corrects data using ecc and returns a tuple.

bch.decode_inplace( data, ecc ) → bitflips

Corrects data using ecc in place, returning the number of bitflips.

bch.decode_syndromes( data, syndromes ) → ( bitflips, data )

Corrects data using a sequence of syndromes, of t*2 elements, returning a tuple.

bch.compute_even_syndromes( syndromes ) → syndromes

Computes even syndromes from odd ones. Takes and returns a sequence of t*2 elements.

bch.ecc_bytes

A readonly field; the number of bytes an ecc takes up.

bch.ecc_bits

A readonly field; the number of bits an ecc takes up.

bch.m

A readonly field; the Galois field order.

bch.n

A readonly field; the maximum codeword size in bits.

bch.syndromes

A readonly field; a tuple of syndromes after performing a correct operation.

bch.t

A readonly field; the number bit errors that can be corrected.

Usage Example

import bchlib
import hashlib
import os
import random

# create a bch object
BCH_POLYNOMIAL = 8219
BCH_BITS = 16
bch = bchlib.BCH(BCH_POLYNOMIAL, BCH_BITS)

# random data
data = bytearray(os.urandom(512))

# encode and make a "packet"
ecc = bch.encode(data)
packet = data + ecc

# print hash of packet
sha1_initial = hashlib.sha1(packet)
print('sha1: %s' % (sha1_initial.hexdigest(),))

def bitflip(packet):
    byte_num = random.randint(0, len(packet) - 1)
    bit_num = random.randint(0, 7)
    packet[byte_num] ^= (1 << bit_num)

# make BCH_BITS errors
for _ in range(BCH_BITS):
    bitflip(packet)

# print hash of packet
sha1_corrupt = hashlib.sha1(packet)
print('sha1: %s' % (sha1_corrupt.hexdigest(),))

# de-packetize
data, ecc = packet[:-bch.ecc_bytes], packet[-bch.ecc_bytes:]

# correct
bitflips = bch.decode_inplace(data, ecc)
print('bitflips: %d' % (bitflips))

# packetize
packet = data + ecc

# print hash of packet
sha1_corrected = hashlib.sha1(packet)
print('sha1: %s' % (sha1_corrected.hexdigest(),))

if sha1_initial.digest() == sha1_corrected.digest():
    print('Corrected!')
else:
    print('Failed')
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].