Created
March 4, 2019 15:39
-
-
Save praetoriansentry/03b6dc2e68e174ffd8168aef7d85f910 to your computer and use it in GitHub Desktop.
Program to find crc32 collision
This file contains hidden or 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
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") | |
} |
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
@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!