Close

Do you speak (insert programming language name here) ?

A project log for PEAC Pisano with End-Around Carry algorithm

Add X to Y and Y to X, says the song. And carry on.

Yann Guidon / YGDESYann Guidon / YGDES 09/12/2022 at 00:090 Comments

My latest article is published and it's a killer !

https://connect.ed-diamond.com/gnu-linux-magazine/glmf-259/l-interminable-quete-du-parfait-petit-checksum-analyse-comparee

It will be fully open around mid-2023. It packs a thorough analysis of existing checksums to deduce/develop the structure and the theory of PEAC checksums. A must-read for anyone who understands French and wants to develop or implement their own checksum!

So I looked around and found that PEAC was picked up by https://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums. I'd like to contribute a coding example but so far I have only coded it in C, asm and JS. Who wants to make other versions of the checksum in Python, Perl, Pascal, ...Psomethingelse ?

DavidCary, if you read this, here's a first snippet to add to the PEAC page:

// PEAC16x2 algorithm, not unrolled.
// Good practice : Pad the end of the buffer
// with 2 words (can be 0) to increase mixing.

#include <stdint.h>

uint32_t  PEAC16x2(int len, uint16_t *src) {
  uint16_t X=0xABCD;
  uint32_t Y=0x4567,
    C=len;  // add the size of the buffer to the checksum

  while (len > 0) {
    C += X;
    len--;
    C += Y;
    Y  = X + *src;
    X  = C & 0xFFFF;
    C >>= 16;
    src++;
  }
  // return 32 bits
  return X | (Y << 16);
} 

The JavaScript version is almost identical, if we modify the declaration, the data types and the array indexing.

// PEAC16x2 algorithm, not unrolled, in JS.

function PEAC16x2(len, src) {
  var X=0xABCD,
    Y=0x4567,
    C=len,
    i=0;

  while (len > 0) {
    C += X + Y;
    len--;
    Y  = X + src[i++];
    X  = C & 0xFFFF;
    C >>= 16;
  }
  return X | (Y << 16);
}

What's next ?

Discussions