def shorten(url): if not url: raise ValueError('url is empty') # Generate a checksum seed = binascii.crc32(url.encode('utf8')) # Base62 encode it in order to get the url id return base62.encode(seed)
def short_url(lastid): """ This function will generate short url based on last autoincremented id from table here we are adding 100000000000 as we want to generate 7 character long unique id :param lastid: last autoincremented id from table :return: short url """ number = lastid + 100000000000 bs62encoded = base62.encode(number) return 'https://abc.com/{id}'.format(id=str(bs62encoded))
def createTeam(): if not isRequestValid(request.headers.get('googleID')): return make_response(jsonify({'status': 'User Does Not Exist!'}), 401) timestamp = int(round(time.time() * 1000)) code = base62.encode(timestamp) team_name = request.args.get('teamName') googleID = request.headers.get('googleID') data = createTeamDAO(googleID, code, timestamp, team_name) return make_response(jsonify(data), 201)
def generate_code(self): start_code = BASE62_ALPHABET[1] + BASE62_ALPHABET[0] * (self.CODE_LENGTH - 1) end_code = BASE62_ALPHABET[-1] * self.CODE_LENGTH start_integer_code, end_integer_code = [int(base62.decode(edge)) for edge in [start_code, end_code]] integer_code = randrange(start_integer_code, end_integer_code) code = base62.encode(integer_code) return code
def generate_id(): """Generate 128 bit UUID encoded in base 62 See: https://www.contentfulcommunity.com/t/support-for-standard-uuids/1635 Returns: str : generated ID. """ uuid_hex = str(uuid.uuid4()).replace('-', '') uuid_int = int(uuid_hex, 16) return base62.encode(uuid_int)
def __init__(self, name=None, **kwargs): """ Parameters ---------- name: str or None, optional, default None A name for the node. Very useful for debugging but not necessary. Each node's name in a tree should be unique. If None, a unique name is generated. """ self.name = name if not self.name: base62.sign = "_" self.name = "n_" + base62.encode(id(self))
def GenerateShortUrl(self, url): cnx = mysql.connector.connect(host="172.17.0.2", user="******", passwd="pass", db="url_shortner") cursor = cnx.cursor(dictionary=True) cursor.execute( "INSERT INTO urls (hash, url) VALUES('','{0}')".format(url)) id = cursor.lastrowid hash = base62.encode(id) cursor.execute("UPDATE urls SET hash='{0}' WHERE id='{1}'".format( hash, id)) cnx.commit() cursor.close() cnx.close() return hash
def encode_submission_id(seed, or_fail=True) -> Optional[str]: """Encodes a seed and returns the corresponding submission ID # Arguments seed: int in the range 62^5 <= seed <= 62^6-1 or_fail: If True, raises a Value error instead of returning None """ try: if not isinstance(seed, int): raise ValueError() if 62 ** 5 <= seed <= 62 ** 6 - 1: return base62.encode(seed) raise ValueError() except (ValueError, TypeError): if or_fail: raise ValueError("Seed has to lie in range 62^5 <= seed <= 62^6-1") return None
def get_unique_post_path(post_header): now = datetime.datetime.now() now_integer_value = int( '{}{:02d}{:02d}{:02d}{:02d}{:02d}{:06d}'.format( now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond, ), ) return '{}-{}'.format( slugify(post_header), base62.encode(now_integer_value), )
def random64(): return base62.encode(random.randint(9, 999999999999999999999999))
def main(): PROGRAM_NAME = "bing2" SLEEP_TIME = 1 HOW_TO = """bing2 - smartened (brute)Bing Use for targeted patterned attack""" if len(sys.argv) != 4: #-1 print(HOW_TO) print("USAGE: python " + PROGRAM_NAME + ".py <URL> <min> <max>") print("brute_min & brute_max in base62, ie case sensitive") print("Note: length is picked up from min&max, so pass args correctly") print("Note: base62 is as follows: numbers->CAPITALS->lowercase") print("For example: python " + PROGRAM_NAME + ".py http://pastebing.ns.agency/raw/2uKYCmrA 0m Fz") else: # init URL = str(sys.argv[1]) length = max(len(sys.argv[2]), len(sys.argv[3])) brute_min = int(base62.decode(sys.argv[2])) brute_max = int(base62.decode(sys.argv[3])) logname = PROGRAM_NAME + "_" + getUnixTime() + ".log" log = open(logname, "a+") cookies = {"zid": "z5214048", "token": "???", "session": "???"} headers = {"Upgrade-Insecure-Requests": "1"} work = brute_max - brute_min bar = ProgressBar(work, max_width=40) # print for user print(PROGRAM_NAME + " initialised") print("URL: " + URL) print("Note: base62 is as follows: numbers->CAPITALS->lowercase") print("stdout will be logged to " + logname) print("the bruteforce will start in 3s") # allow user to change brute_mind time.sleep(3) #payload i = 0 for i in range(work + 1): k = i + brute_min k_string = base62.encode(k) # convertion to the text k_string = k_string.zfill(length) #decorating r = requests.get(URL + k_string, cookies=cookies, headers=headers) txt = r.text # https://docs.python.org/3/library/zlib.html SAYS #'An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much more quickly' #'Changed in version 3.0: Always returns an unsigned value' => GOOD txt_hash = toHexCustom(zlib.adler32(txt.encode('utf-8'))) # write to payload listings f_payload = open("pay_" + txt_hash + ".txt", "a+") f_payload.write(k_string + "\n") f_payload.close() # if no transcription => first time resp encountered if not (os.path.isfile("plain_" + txt_hash + ".txt")): # write to plaintext transcription f_plain = open("plain_" + txt_hash + ".txt", "w+", encoding="utf-8") f_plain.write(txt) f_plain.close() # now log stuff whatToLog = "[N]" + k_string + "; New hash found! Check: " + txt_hash + " (" + str( r.status_code) + ")" log.write(whatToLog + "\n") print(whatToLog) # if hash already encountered else: # boring log, what else to do whatToLog = "[B]" + k_string + ": " + txt_hash + " (" + str( r.status_code) + ")" log.write(whatToLog + "\n") print(whatToLog) bar.numerator = i print(str(bar)) #sys.stdout.flush() #myCoolTitle = PROGRAM_NAME+" "+k_string #os.system("title "+myCoolTitle) #https://stackoverflow.com/a/10229529 #time.sleep(SLEEP_TIME/1000) #payload (for-loop) over whatToLog = "[F] Fin" log.write(whatToLog + "\n") print(whatToLog) log.close()
def encode_to_base62(obj_id): ''' First decodes the hexadecimal object ID and then encodes it to base 62 which will be used as the short URL ID ''' return base62.encode(base16.decode(str(obj_id).upper()))
def main(): PROGRAM_NAME = "bing" if len(sys.argv) != 3: print("USAGE: python "+PROGRAM_NAME+".py <URL> <length>") print("For example: python "+PROGRAM_NAME+".py http://pastebing.ns.agency/raw/2uKYCmrAg 1") else: # init # https://stackoverflow.com/a/16060908 URL = str(sys.argv[1]) brute_len = int(sys.argv[2]) SLEEP_TIME = 1/1000 logname = PROGRAM_NAME+"_"+str(int(time.time()))+".log" log = open(logname, "a+") cookies = { "zid": "z5214048", "token": "88d60373d31db28d31a54a184759c1e4bab6a60a48c54f7eda48459b8b692287", "session": "eyJ1c2VybmFtZSI6ImNvb2tpZXMgIn0.D20t9w.Yit2yv7ojsbNSBmMn2-aBvGla1c" } brute_min = 0 brute_max = (62**brute_len)-1 work = brute_max-brute_min bar = ProgressBar(work, max_width=40) # print for user print(PROGRAM_NAME+" initialised") print("URL: "+URL) print("stdout will be logged to "+logname) print("the bruteforce will start in 3s") # allow user to change mind time.sleep(3) #payload i = 0 for i in range(work+1): k=i+brute_min k_string = base62.encode(k) # convertion to the text k_string = k_string.zfill(brute_len) #decorating r = requests.get(URL+k_string, cookies=cookies) txt = r.text # https://docs.python.org/3/library/zlib.html SAYS #'An Adler-32 checksum is almost as reliable as a CRC32 but can be computed much more quickly' #'Changed in version 3.0: Always returns an unsigned value' => GOOD txt_hash = toHexCustom(zlib.adler32(txt.encode('utf-8'))) # write to payload listings f_payload = open("bings_"+txt_hash+".txt", "a+") f_payload.write(k_string+"\n") f_payload.close() # if no transcription => first time resp encountered if not(os.path.isfile("plain_"+txt_hash+".txt")): # write to plaintext transcription f_plain = open("plain_"+txt_hash+".txt", "w+", encoding="utf-8") f_plain.write(txt) f_plain.close() # now log stuff whatToLog = "[N]"+k_string+"; New hash found! Check file: "+"plain_"+txt_hash+".txt" log.write(whatToLog+"\n") print(whatToLog) # if hash already encountered else: # boring log, what else to do whatToLog = "[B]"+k_string+": "+txt_hash+" ("+str(r.status_code)+")" log.write(whatToLog+"\n") print(whatToLog) bar.numerator = i print(str(bar)) #sys.stdout.flush() myCoolTitle = PROGRAM_NAME+" "+k_string os.system("title "+myCoolTitle) #https://stackoverflow.com/a/10229529 #time.sleep(SLEEP_TIME/1000) #payload (for-loop) over whatToLog = "[F] Fin" log.write(whatToLog+"\n") print(whatToLog) log.close()
def keccakmod(s): rawhash = hashlib.sha3_224(s.encode('utf-8')).hexdigest().upper() modhash = base62.encode(base16.decode(rawhash)) return modhash
def toBase62(num): encoded = base62.encode(num) return encoded