Search code examples
number-theoryerror-correction

Code that maps numbers from one number to another with where each number has a distance greater than 1


I need to tag a load of books with a unique id. Because human error would really mess with the system i need the code to detect if one of the numbers is wrong. That means that no two elements of the code can have a hamming distance of 1. Or have a parity check method or something again such that some errors can be detected. I would normally post what I've done so far, but I don't know where to start really.

Thanks


Solution

  • If you are dealing with human readable data, I would go with something like the Luhn algorithm. This is designed for simple manual computation, as well as resulting in decimal encoded data.

    The problem you will have with binary codes is that they will scramble the data a little. So unless you plan to encode your id's in an image, such as a barcode or QR, it's probably not the right choice. Also, optimal decoders are complicated algorithms, they are certainly not practical to check by hand calculation.

    If you insist on going with a binary code, then you'll have to decide how many bit errors you want to detect. You'll need a hamming distance of at least 2 to detect an error, otherwise a single bit flip will result in the code being transformed into another equally valid code, and the error will go unnoticed. If you want to correct N errors, then you'll need to choose a code with a distance of 2N+1.

    If you are planning to encode hexadecimal digits, then you'll need 4-bits per digit storage, which will require a code with 9-bits of redundancy per message in order to correct a single digit error. I'm not even sure such a perfect codes exists, and in reality you might find you need more redundancy to equally protect all bits.