mirror of
https://codeberg.org/SiB64/bch4369.git
synced 2026-05-01 16:04:25 +02:00
Compare commits
2 commits
50200520b1
...
df2bd55855
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df2bd55855 | ||
|
|
7f5400fa08 |
4 changed files with 15 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
galois-git/
|
galois-git/
|
||||||
galois
|
galois
|
||||||
|
__pycache__
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ This code can correct up to 8 bit errors.
|
||||||
|
|
||||||
## AVR
|
## AVR
|
||||||
|
|
||||||
Here you find space efficient code for an AVR µC, in C and assmebler.
|
Here you find space efficient code for an AVR µC, in C and assembler.
|
||||||
|
|
||||||
## Python
|
## Python
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
17
bch4369.py
17
bch4369.py
|
|
@ -51,8 +51,11 @@ class bch4369():
|
||||||
def load_galois(self):
|
def load_galois(self):
|
||||||
if self.galois is not None:
|
if self.galois is not None:
|
||||||
return
|
return
|
||||||
|
print("BCH4369: loading module galois …", file=stderr)
|
||||||
from galois import BCH, GF
|
from galois import BCH, GF
|
||||||
|
print("BCH4369: … building BCH(4369) …", file=stderr)
|
||||||
self.galois = BCH(4369, 4369-128, extension_field=GF(2**16))
|
self.galois = BCH(4369, 4369-128, extension_field=GF(2**16))
|
||||||
|
print("BCH4369: … done.", file=stderr)
|
||||||
|
|
||||||
def decode(self, *a, **aa):
|
def decode(self, *a, **aa):
|
||||||
self.load_galois()
|
self.load_galois()
|
||||||
|
|
@ -78,13 +81,19 @@ class bch4369():
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
class BCHError(IOError):
|
||||||
|
pass
|
||||||
|
|
||||||
def fix_page(self, b, what='codeword'):
|
def fix_page(self, b, what='codeword'):
|
||||||
a, e = self.decode(self.bytes2bits(self.salt + b), output=what, errors=True)
|
a, e = self.decode(self.bytes2bits(self.salt + b), output=what, errors=True)
|
||||||
m = self.bits2bytes(a)
|
m = self.bits2bytes(a)
|
||||||
if e:
|
if not e:
|
||||||
print(f"BCH4369: {e} errors corrected", file=stderr)
|
return b
|
||||||
if m[:len(self.salt)] != self.salt:
|
if e<0:
|
||||||
print(f"BCH4369: error in the salt {self.salt!r} → {m[:len(self.salt)]!r}", file=stderr)
|
raise self.BCHError(f"BCH4369: {e=}: cannot correct errors")
|
||||||
|
print(f"BCH4369: {e} errors corrected", file=stderr)
|
||||||
|
if m[:len(self.salt)] != self.salt:
|
||||||
|
print(f"BCH4369: error in the salt {self.salt!r} → {m[:len(self.salt)]!r}", file=stderr)
|
||||||
return m[len(self.salt):]
|
return m[len(self.salt):]
|
||||||
|
|
||||||
bitv = (0x80 >> arange(8, dtype=uint8)).reshape((1,8))
|
bitv = (0x80 >> arange(8, dtype=uint8)).reshape((1,8))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue