Skip to content

Commit

Permalink
added main routine to rs.py
Browse files Browse the repository at this point in the history
  • Loading branch information
brownan committed Nov 5, 2010
1 parent 35f30ee commit 69a388e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rs.py
Expand Up @@ -14,6 +14,17 @@
message are dropped. Be careful if encoding binary data, pad the data yourself
to k bytes per block to avoid problems. Also see the nostrip option to
decode().
When called as a script, this file encodes data from standard in and outputs it
to standard out, using the standard RS code 255,223. This is suitable for
encoding text and trying it out, but don't try to encode binary data with it!
When encoding, it outputs blocks of 255 bytes, 223 of them are data (padded
with leading null bytes if necessary) and then 32 bytes of parity data.
Use the -d flag to decode data on standard in to standard out. This reads in
blocks of 255 bytes, and outputs the decoded data from them. If there are less
than 16 errors per block, your data will be recovered.
"""

class RSCoder(object):
Expand Down Expand Up @@ -355,3 +366,21 @@ def _forney(self, omega, X):

Y.append(Yl)
return Y

if __name__ == "__main__":
import sys
coder = RSCoder(255,223)
if "-d" in sys.argv:
method = coder.decode
blocksize = 255
else:
method = coder.encode
blocksize = 223

while True:
block = sys.stdin.read(blocksize)
if not block: break
code = method(block)
sys.stdout.write(code)


2 comments on commit 69a388e

@felix021
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'm a little curious that why you choose alpha=3 as the primitive element of GF(256). That choice makes your implement not compatible with the matlab one, which uses alpha=2 :'(

@brownan
Copy link
Owner Author

@brownan brownan commented on 69a388e Apr 23, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.