mirror of
https://codeberg.org/SiB64/bch4369.git
synced 2026-05-01 16:04:25 +02:00
Compare commits
No commits in common. "df2bd5585523c6eca9d1955466819daa89c2c55b" and "50200520b1e56bade37ec489287c1bc89c7e1ddb" have entirely different histories.
df2bd55855
...
50200520b1
4 changed files with 5 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,2 @@
|
|||
galois-git/
|
||||
galois
|
||||
__pycache__
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ This code can correct up to 8 bit errors.
|
|||
|
||||
## 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
|
||||
|
||||
|
|
|
|||
BIN
__pycache__/bch4369.cpython-313.pyc
Normal file
BIN
__pycache__/bch4369.cpython-313.pyc
Normal file
Binary file not shown.
11
bch4369.py
11
bch4369.py
|
|
@ -51,11 +51,8 @@ class bch4369():
|
|||
def load_galois(self):
|
||||
if self.galois is not None:
|
||||
return
|
||||
print("BCH4369: loading module galois …", file=stderr)
|
||||
from galois import BCH, GF
|
||||
print("BCH4369: … building BCH(4369) …", file=stderr)
|
||||
self.galois = BCH(4369, 4369-128, extension_field=GF(2**16))
|
||||
print("BCH4369: … done.", file=stderr)
|
||||
|
||||
def decode(self, *a, **aa):
|
||||
self.load_galois()
|
||||
|
|
@ -81,16 +78,10 @@ class bch4369():
|
|||
return True
|
||||
return False
|
||||
|
||||
class BCHError(IOError):
|
||||
pass
|
||||
|
||||
def fix_page(self, b, what='codeword'):
|
||||
a, e = self.decode(self.bytes2bits(self.salt + b), output=what, errors=True)
|
||||
m = self.bits2bytes(a)
|
||||
if not e:
|
||||
return b
|
||||
if e<0:
|
||||
raise self.BCHError(f"BCH4369: {e=}: cannot correct errors")
|
||||
if e:
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue