Last active
March 6, 2022 15:48
-
-
Save fabiolimace/72a529c4b219dd9cfe4d96227da9eb8a to your computer and use it in GitHub Desktop.
Finds for mathes of a specific word in a series of random base-n UUIDs for Python
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
#!/bin/env python3 | |
import math | |
import string | |
from uuid import UUID, uuid4 | |
b32 = "abcdefghijklmnopqrstuvwxyz234567" | |
b36 = "0123456789abcdefghijklmnopqrstuvwxyz" | |
b48 = "ABCDEFGHJKLMNOPQRSTVWXYZabcdefghijkmnopqrstvwxyz" | |
b52 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
b58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" # btc | |
b62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
b64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" # url | |
def basen(number, alphabet): | |
output = "" | |
base = len(alphabet) | |
while number: | |
output += alphabet[number % base] | |
number //= base | |
return output[::-1] | |
def encode(uuid, alphabet): | |
num = uuid.int | |
pad = alphabet[0] | |
base = len(alphabet) | |
length = int(math.ceil(128 / (math.log(base) / math.log(2)))) | |
encoded = basen(num, alphabet) | |
return encoded.rjust(length, pad) | |
""" | |
Looks for mathes of a specific word in a series of random base-n UUIDs. | |
""" | |
def find_matches(alphabet, word = 'test', series = 1000000): | |
i = 0 | |
f = 0 | |
print(f'Finding mathes for \'{word}\' in a series of {series} base-{len(alphabet)} UUIDs.') | |
print(f'Alphabet: \'{alphabet}\'.') | |
while i < series: | |
i +=1 | |
string = encode(uuid4(), alphabet) | |
if string.lower().find(word.lower()) > -1: | |
print(f'- Match: {string}') | |
f += 1 | |
print(f'Found {f} matches.\n') | |
find_matches(b32) | |
find_matches(b36) | |
find_matches(b48) | |
find_matches(b52) | |
find_matches(b58) | |
find_matches(b62) | |
find_matches(b64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result for loops of 10 million UUIDs:
In summary:
Output: