Created
June 15, 2015 15:57
-
-
Save derand/564ee1e1f87ba9c5f001 to your computer and use it in GitHub Desktop.
Search beautiful imageboard tripcodes.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import re | |
import string | |
from crypt import crypt | |
import random | |
import sys | |
def tripcode(pw): | |
pw = pw.encode('sjis', 'ignore') \ | |
.replace('"', '"') \ | |
.replace("'", '\'') \ | |
.replace('<', '<') \ | |
.replace('>', '>') \ | |
.replace(',', ',') | |
salt = re.sub(r'[^\.-z]', '.', (pw + 'H..')[1:3]) | |
salt = salt.translate(string.maketrans(r":;=?@[\]^_`", "ABDFGabcdef")) ####]" fix colors on sublime2 | |
return crypt(pw, salt)[-10:] | |
def _rand(n=16, chars='ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuwxyz1234567890-/\\".'): | |
return ''.join(random.choice(chars) for _ in range(n)) | |
def search(reg): | |
chars = 'ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuwxyz1234567890.' | |
r = re.compile(reg) | |
i = 0 | |
while True: | |
t = _rand(chars=chars) | |
code = tripcode(t) | |
if r.match(code): | |
print t, code, i | |
break | |
s = set(code) | |
if len(s) < 4: | |
print t, code, i | |
i += 1 | |
return (t, code, i) | |
if __name__=='__main__': | |
if len(sys.argv) > 1: | |
for a in sys.argv[1:]: | |
search(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example:
$ time python search_tripcode.py "^[Cc]irno[\./9]"