Skip to content

Instantly share code, notes, and snippets.

@praetoriansentry
Created March 4, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save praetoriansentry/03b6dc2e68e174ffd8168aef7d85f910 to your computer and use it in GitHub Desktop.
Save praetoriansentry/03b6dc2e68e174ffd8168aef7d85f910 to your computer and use it in GitHub Desktop.
Program to find crc32 collision
package main
import (
"fmt"
"hash/crc32"
"io/ioutil"
"log"
"runtime"
"strings"
"sync"
)
var routines uint32 = 8
func main() {
runtime.GOMAXPROCS(int(routines))
var wg sync.WaitGroup
var i uint32
for i = 0; i < routines; i = i + 1 {
wg.Add(1)
go func(buc uint32) {
dataFile, err := ioutil.ReadFile("quine-crc.js")
if err != nil {
log.Fatal(err)
}
baseTemplateString := string(dataFile[:])
parts := strings.Split(baseTemplateString, "{{Pad}}")
var pad uint32 = 681180860
for {
pad += 1
if pad == 0 {
wg.Done()
break
}
if pad%routines != buc {
continue
}
curQuine := strings.Join(parts, fmt.Sprintf("0x%08x", pad))
cksum := crc32.ChecksumIEEE([]byte(curQuine))
if cksum == pad {
log.Printf("Found it dec: %d hex: 0x%08x", pad, pad)
log.Println(cksum)
log.Printf("%s", curQuine)
log.Fatal("done")
break
}
if pad%1000000 == 0 {
log.Printf("%d", pad)
log.Printf("%s", curQuine)
}
}
}(i)
}
wg.Wait()
log.Println("Finished without finding collision")
}
@hdf
Copy link

hdf commented Oct 31, 2022

@praetoriansentry Can I ask, why do you start the pad with 681180860? It seems like a pretty random number, why would 0 be worse? Thank you!

@praetoriansentry
Copy link
Author

I'm not sure. I'm just guessing, but probably what I did was hard code the first collision that I found so that I could re-run it quickly for verification purposes. I would guess a 0 is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment