Compare commits

..

No commits in common. "df2bd5585523c6eca9d1955466819daa89c2c55b" and "50200520b1e56bade37ec489287c1bc89c7e1ddb" have entirely different histories.

4 changed files with 5 additions and 15 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
galois-git/ galois-git/
galois galois
__pycache__

View file

@ -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 assembler. Here you find space efficient code for an AVR µC, in C and assmebler.
## Python ## Python

Binary file not shown.

View file

@ -51,11 +51,8 @@ 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()
@ -81,16 +78,10 @@ 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 not e: if e:
return b
if e<0:
raise self.BCHError(f"BCH4369: {e=}: cannot correct errors")
print(f"BCH4369: {e} errors corrected", file=stderr) print(f"BCH4369: {e} errors corrected", file=stderr)
if m[:len(self.salt)] != self.salt: if m[:len(self.salt)] != self.salt:
print(f"BCH4369: error in the salt {self.salt!r}{m[:len(self.salt)]!r}", file=stderr) print(f"BCH4369: error in the salt {self.salt!r}{m[:len(self.salt)]!r}", file=stderr)