Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
I don't understand this. I can't think of any issue that would affect sum unpack 'W*', decode 'UTF-8', $utf8 that wouldn't also affect sum unpack 'C*', $utf8

Let's start with the simple case.

With bytes, the sum-of-bytes checksum will detect any single bit corruption in the string.

Can you say that there is no single bit corruption that cannot cause (say) a 4-byte encoded character to be seen as (say) a valid sequence of one 1-byte encoded character and one 3-byte encoded character; or a valid sequence of two 2-byte encoded characters; who's code-points happen to sum to the same numeric value as the code-point of the original uncorrupted 4-byte character?


With 2-bit characters each of the four characters can be transposed to 2 other characters as a result of a single-bit corruption, giving 4 possibilities for false positives for every 2-characters in the string. For 3-bit characters that becomes 8 possibilities for every 2 bytes

With 8-bit bytes values, that becomes 256 possible undetectable pairs of single-bits corruptions for every 2 characters in the string. (Which is what makes sum-the-bytes checksumming so dire.)

With 1,112,064 code-point values, there are obviously going to be far more permutations. It isn't going to be be direct 2**1112864 because many of the corruptions will result in invalid characters, which will reduce the total. But then there are the possibilities of single characters becoming 2 valid characters or two becoming one (which cannot happen with bytes). So, whilst many of those n-byte to (valid) m-byte corruptions won't sum to the the same value, some will.

Overall, it is my gut-feel assessment that the possibilities for undetected self-cancelling single/double/tripe/quad/quin/.... corruptions is far, far higher. (An interesting problem to try and verify this assertion!)

For that reason, amongst others, there seems to be no benefit in calculating checksums in terms of Unicode ordinals rather than bytes.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: Binary value of string by BrowserUk
in thread Binary value of string by packetstormer

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.