Created
November 15, 2016 11:36
-
-
Save hops/348169dad641d95a062a23bdabe607b6 to your computer and use it in GitHub Desktop.
adler32 collider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ---------------------------------------------------------------------------- | |
* "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