Reed-solomon updated

The reed-solomon library is updated, bug fix and simplify code.

Reed Solomon(rs) is a error recover algorithm, use rs to encode a piece of data, generate 2t's length's extra data to append to the original data. So can recover t's length's randrom error.

QR code use it to recover polluted data.

For example: you use rs to generate 10's extra data to suffix, then you can recover any 5 errors at most.

Example:

original_data: Chen Xiao is just a programmer.
polluted_data: Chen Xiao is a fabulous artist.
rs-encode(original_data, 34) = ����Z���o!IA�򈵮���� �L��.�.e.
encoded_polluted_data: Chen Xiao is a fabulous artist.����Z���o!IA�򈵮���� �L��.�.e.
rs-decode(encoded_polluted_data, 34) = Chen Xiao is just a programmer.����Z���o!IA�򈵮���� �L��.�.e.

code is below:

(let* ([original_data "Chen Xiao is just a programmer."]
       [polluted_data "Chen Xiao is a fabulous artist."]
       [rs_code
        (rs-encode (bytes->list (string->bytes/utf-8 original_data)) 34)]
       [encoded_polluted_data
        (bytes-append
         (string->bytes/utf-8 polluted_data)
         (list->bytes rs_code))])

  (printf "original_data: ~a\n" original_data)
  
  (printf "polluted_data: ~a\n" polluted_data)

  (printf "rs-encode(original_data, 34) = ~a\n" (list->bytes rs_code))

  (printf "encoded_polluted_data: ~a\n" encoded_polluted_data)

  (printf "rs-decode(encoded_polluted_data, 34) = ~a\n" (list->bytes (rs-decode (bytes->list encoded_polluted_data) 34))))
2 Likes

Is there an option to encode the sufix as base64 or hexadecimal?

reed-solomon can recover any place's error, so suffix and original string is a whole thing.

Of course, you can base64 the whole byte list or any other format, convert back to byte list when you need decode.