Skip to content

Instantly share code, notes, and snippets.

@mmalex
Created September 15, 2011 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmalex/1219860 to your computer and use it in GitHub Desktop.
Save mmalex/1219860 to your computer and use it in GitHub Desktop.
untest implementation of @deplinenoise's amiga checksum
#include <stdio.h>
#include <arpa/inet.h> // for htonl
int main(int argc, char **argv){
unsigned int c=0,d,i,block[256]={0};
fread(block,1,1024,fopen(argv[1],"rb"));
for (i=0;i<256;++i)
if (c > (d=c+htonl(block[i]))) c=d+1; else c=d;
block[1]=htonl(c)^0xffffffff;
fwrite(block,1,1024,fopen(argv[2],"wb"));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment