Created
February 14, 2022 20:33
-
-
Save valkheim/043d134fe3837608afe1201dfcffe554 to your computer and use it in GitHub Desktop.
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
import datetime | |
import hashlib | |
import random | |
import struct | |
def dga(tlds: [str], seed: int, seq_init: int, seq_len: int, dt: int = None) -> str: | |
if dt is None: | |
dt = datetime.datetime.today().toordinal() | |
hash_str = str(dt).encode("ascii") + str(seed).encode("ascii") | |
dt_hash = hashlib.sha256(hash_str) | |
dt_hash_str = dt_hash.hexdigest() | |
a, b = struct.unpack("2B", dt_hash_str.encode("ascii")[:2]) | |
a %= 9 | |
l = min(a, b) | |
r = max(a, b) | |
l = max(l, 32) | |
dt_hash_substr = dt_hash_str[l:r] | |
seed_str = chr(((seed % seq_len) + seq_init) % 0xFF) | |
tld = tlds[seed % len(tlds)] | |
return f"{dt_hash_substr}{seed_str}.{tld}" | |
date = datetime.datetime.strptime("Feb 14 2022", "%b %d %Y").toordinal() | |
tlds = [ | |
"icu", | |
"us", | |
"name", | |
"xyz", | |
"work", | |
"club", | |
"host", | |
"pw", | |
"website", | |
"space", | |
"fun", | |
"info", | |
"press", | |
"agency", | |
"pro", | |
"rocks", | |
"world", | |
"online", | |
"today", | |
"life", | |
"live", | |
] | |
random.shuffle(tlds) | |
seed = random.randint(10, 1000) | |
seq_init = ord("a") | |
seq_len = 26 | |
print("Date: ", date) | |
print("TLDs: ", ",".join(tlds)) | |
print("seed: ", seed) | |
print("seq init: ", seq_init) | |
print("seq length: ", seq_len) | |
print("=" * 25) | |
i = seed | |
while True: | |
i += 1 | |
print(dga(tlds, i, seq_init, seq_len, date)) | |
if i % 25 == 0: | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment