Created
September 15, 2023 11:20
-
-
Save Mihonarium/51d8503714d66c3bab09a8158d6f1a70 to your computer and use it in GitHub Desktop.
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 ( | |
"crypto/sha256" | |
"encoding/hex" | |
"fmt" | |
"log" | |
"sync" | |
) | |
var prefix []byte | |
func main() { | |
prefixString := "00000000" // we compare only to the first 7 hex symbols, see compareHashPrefix | |
prefix = make([]byte, len(prefixString)/2) | |
_, err := hex.Decode(prefix, []byte(prefixString)) | |
if err != nil { | |
log.Fatalf("Failed to decode prefix: %v", err) | |
} | |
fmt.Println("Prefix:", prefix) | |
// Arrays of synonyms for different words in the base sentence | |
synonyms := [][]string{ | |
{"Beneath the veil of", "Within the depths of", "Underneath the cover of"}, | |
{"digital", "binary", "cyber"}, | |
{"realms,", "domains,", "territories,"}, | |
{"in a delicate", "within a gentle", "amidst a soft", "in a subtle"}, | |
{"dance of zeros,", "rhythm of silence,", "symphony of stillness,"}, | |
{"seven", "sevenfold", "heptadic"}, | |
{"zeros", "nulls", "voids"}, | |
{"emerge to", "surfacing to", "rise and"}, | |
{"conjure a", "weave a", "craft an", "paint a"}, | |
{"serene", "tranquil", "calm", "peaceful"}, | |
{"canvas.", "landscape.", "portrait.", "masterpiece."}, | |
{"Like celestial", "Resembling celestial", "As if celestial"}, | |
{"beacons in", "guiding lights in", "illuminations amidst"}, | |
{"a luminous", "an ethereal", "a celestial"}, | |
{"night sky,", "universe,", "cosmos,"}, | |
{"they manifest", "they materialize", "they come to life"}, | |
{"in the form of", "as", "morphing into"}, | |
{"an arcanum", "a mystery", "an enigma"}, | |
{"of seven-fold", "with seven", "with heptadic", "with sevenfold"}, | |
{"serenity,", "tranquility,", "stillness,"}, | |
{"with", "holding", "bearing"}, | |
{"divine", "sacred", "holy"}, | |
{"grace.", "elegance.", "majesty."}, | |
} | |
// Convert the string to a byte slice | |
/* targetHashPrefix, err := hex.DecodeString(targetHashPrefixStr) | |
if err != nil { | |
panic(err) | |
} */ | |
for i := 0; i < len(synonyms)-1; i++ { | |
for j := 0; j < len(synonyms[i]); j++ { | |
if synonyms[i][j][len(synonyms[i][j])-1] != '\n' { | |
synonyms[i][j] += " " | |
} | |
} | |
} | |
totalCombinations := 1 | |
for _, syns := range synonyms { | |
totalCombinations *= len(syns) | |
} | |
fmt.Println("Total combinations:", totalCombinations) | |
var wg sync.WaitGroup | |
results := make(chan []byte, 20) | |
done := make(chan bool) | |
threads := 16 | |
for i := 0; i < threads; i++ { | |
wg.Add(1) | |
go func(offset int) { | |
defer wg.Done() | |
for j := offset; j < totalCombinations; j += threads { | |
sentence := buildSentence(j, synonyms) | |
hash := sha256.Sum256(sentence) | |
if compareHashPrefix(hash) { | |
results <- sentence | |
return | |
} | |
} | |
}(i) | |
} | |
go func() { | |
wg.Wait() | |
close(results) | |
done <- true | |
close(done) | |
}() | |
for { | |
select { | |
case sentence := <-results: | |
fmt.Println("Found a match!") | |
fmt.Println("Sentence:", string(sentence)) | |
case <-done: | |
return | |
} | |
} | |
} | |
func buildSentence(num int, synonyms [][]string) []byte { | |
var sentence []byte | |
tempI := num | |
for j := 0; j < len(synonyms); j++ { | |
sentence = append(sentence, []byte(synonyms[j][tempI%len(synonyms[j])])...) | |
tempI /= len(synonyms[j]) | |
} | |
return sentence | |
} | |
func compareHashPrefix(hash [32]byte) bool { | |
return hash[0] == prefix[0] && hash[1] == prefix[1] && hash[2] == prefix[2] && (hash[3]&0xf0) == prefix[3]&0xf0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment