Last active
October 9, 2021 15:54
-
-
Save chand1012/0dadb61ed31eb0950cec6344a8ee1d97 to your computer and use it in GitHub Desktop.
Tests to see if there are any MD5 collisions within the valid public IPv4 range. Will eat all your RAM.
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/md5" | |
"encoding/hex" | |
"fmt" | |
) | |
// get the md5 hash of a string | |
func getMd5Hash(text string) string { | |
hasher := md5.New() | |
hasher.Write([]byte(text)) | |
return hex.EncodeToString(hasher.Sum(nil)) | |
} | |
func main() { | |
var hash_table = make(map[string]string) | |
// loop from 1 to 255 | |
for a := 1; a < 256; a++ { | |
if a == 10 { | |
continue | |
} | |
// loop from 1 to 255 | |
for b := 1; b < 256; b++ { | |
if a == 192 && b == 168 { | |
continue | |
} | |
if a == 172 && b >= 16 && b <= 31 { | |
continue | |
} | |
for c := 1; c < 256; c++ { | |
for d := 1; d < 256; d++ { | |
ip := fmt.Sprint(a) + "." + fmt.Sprint(b) + "." + fmt.Sprint(c) + "." + fmt.Sprint(d) | |
hash := getMd5Hash(ip) | |
output, ok := hash_table[hash] | |
if ok { | |
println(output + " " + ip) | |
} else { | |
hash_table[hash] = ip | |
} | |
} | |
} | |
} | |
} | |
} |
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
import hashlib | |
def md5(s): | |
return hashlib.md5(s.encode()).hexdigest() | |
hash_table = {} | |
for a in range(256): | |
if a == 0 or a == 10: | |
continue | |
for b in range(256): | |
if a == 192 and b == 168: | |
continue | |
if a == 172 and b >= 16 and b <= 31: | |
continue | |
for c in range(256): | |
for d in range(256): | |
ip = '.'.join([str(a), str(b), str(c), str(d)]) | |
ip_hash = md5(ip) | |
if ip_hash in hash_table: | |
print(ip, ip_hash, hash_table[ip_hash]) | |
else: | |
hash_table[ip_hash] = ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment