Skip to content

Instantly share code, notes, and snippets.

@hops hops/adler32_col.c
Created Nov 15, 2016

Embed
What would you like to do?
adler32 collider
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* @hops_ch wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Michael Sprecher
* ----------------------------------------------------------------------------
*/
// compile with: gcc -o adler32_col -lz -O3 adler32_col.c
#include <zlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CHARS 0x7e - 0x2f
#define START 0x2f
int main (int argc, char* argv[])
{
if (argc != 3) {
fprintf (stderr, "usage: %s checksum length\n", argv[0]);
return (-1);
}
uLong match = atol(argv[1]);
int len = atoi(argv[2]);
char buf[len + 1];
memset(buf, 0, len + 1);
while(1) {
for (int i = 0; i < len; i++) {
buf[i] = START + (random() % (CHARS));
}
uLong adler = adler32(0L, Z_NULL, 0);
adler = adler32(adler, (Byte *)buf, len);
if (adler == match) {
printf("found collision: %s\n", buf);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.