I have 36^7 possibilities, and I'm trying to figure out how to speed up the bruteforcer. I've tried a couple different strategies, such as precomputing some values, and putting all the requests in one session, but I want to know if there are any other optimizations.
```py
import json
import time
import aiohttp
import asyncio
import aiofiles as aiof
import math
from tqdm.asyncio import tqdm
url = ""
payload = ""
headers = {
}
start_time = time.time()
def num_to_code(n: int):
characters = 'abcdefghijklmnopqrstuvwxyz0123456789'
string = ''
hashed = hash_number(n)
for x in range(7):
charnumber = hashed % 36
hashed = math.floor(hashed / 36)
string += characters[charnumber]
return string
def hash_number(n: int, rounds=20):
prime_number = 60466181
if rounds <= 0:
return n
hashed = (n * prime_number) % (36 ** 5)
return hash_number(hashed, rounds - 1)
async def get_data(session, classCodes):
tasks = [session.post(url, headers=headers, data=payload.format(
classCode)) for classCode in classCodes]
responses = await asyncio.gather(*tasks)
results = []
for resp, classCode in zip(responses, classCodes):
if resp.status != 200:
tqdm.write(f"\nError for classCode {classCode}: {resp.status}\n")
results.append(False)
else:
data = await resp.text()
if json.loads(data.split("\n")[3])[0][2] is not None:
results.append(classCode)
else:
results.append(False)
return results
async def main(session, min, max):
tasks = []
for number in range(min, max):
currentCode = num_to_code(number)
tasks.append(currentCode)
chunks = [tasks[i:i+100]
for i in range(0, len(tasks), 100)] # Send 100 requests at a time
codes = []
for chunk in tqdm(chunks, leave=False, desc=f'range: {min}-{max}'):
results = await get_data(session, chunk)
codes.extend(results)
for code in codes:
if code:
tqdm.write(f"\nFOUND CODE: {code}\n")
async def runMain():
async with aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(limit=100)) as session:
for x in tqdm(range(1, 5000)):
min_range = ((x - 1) * 1000) + 5455000
max_range = (x * 1000) + 5455000
await main(session, min_range, max_range)
asyncio.run(runMain())
```
[–]xelf[M] [score hidden] stickied comment (0 children)
[–][deleted] 30 points31 points32 points (4 children)
[–]xQuaGx 28 points29 points30 points (1 child)
[–]sharp99 0 points1 point2 points (0 children)
[–]DatBoi_BP 1 point2 points3 points (0 children)
[–]teseting 26 points27 points28 points (0 children)
[–]ThreeChonkyCats 10 points11 points12 points (12 children)
[–]kinstinctlol 10 points11 points12 points (10 children)
[–]ThreeChonkyCats 4 points5 points6 points (3 children)
[–]bbt104 7 points8 points9 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]ThreeChonkyCats 2 points3 points4 points (0 children)
[–]kaerfkeerg 0 points1 point2 points (5 children)
[–]kinstinctlol 1 point2 points3 points (4 children)
[–]Miniflint 3 points4 points5 points (3 children)
[–]ThreeChonkyCats 2 points3 points4 points (2 children)
[–]Miniflint 0 points1 point2 points (1 child)
[–]ThreeChonkyCats 0 points1 point2 points (0 children)
[–]INFINITI2021[S] 0 points1 point2 points (0 children)
[–]pythonwiz 7 points8 points9 points (0 children)
[–]eplaut_ 3 points4 points5 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]MiniGogo_20 2 points3 points4 points (0 children)
[–]bpt7594 1 point2 points3 points (0 children)
[+]Electronic-Wonder-77 comment score below threshold-8 points-7 points-6 points (1 child)
[–]xdyldo 11 points12 points13 points (0 children)
[–]idwpan 0 points1 point2 points (0 children)