Compare commits

...

2 commits

Author SHA1 Message Date
Stephan I. Böttcher
df2bd55855 README typo 2026-02-09 09:06:16 +01:00
Stephan I. Böttcher
7f5400fa08 fix_page() raise BCHError 2026-02-09 08:59:37 +01:00
4 changed files with 15 additions and 5 deletions

1
.gitignore vendored
View file

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

Binary file not shown.

View file

@ -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))