Last active
October 25, 2022 23:49
-
-
Save Krewn/d7cb7c17e871da1f46b9b3b2eb41abe9 to your computer and use it in GitHub Desktop.
Sorry for the default image download. Feel free to make modifications before use... Obviously.
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
from urllib import parse | |
import requests | |
from bs4 import BeautifulSoup | |
import hashlib | |
import sys | |
from PIL import Image | |
import shutil | |
def findFlavor(attrs): | |
flavorsOfSalt = ["salt","salty","sodium","Na","aProductOfAnAcidBaseReaction"] | |
idx = 0 | |
while idx < len(flavorsOfSalt): | |
if not (flavorsOfSalt[idx] in attrs.keys()): | |
return flavorsOfSalt[idx] | |
idx = 0 | |
suffix = "0" | |
while "salt"+suffix in attrs.keys(): | |
idx += 1 | |
suffix = hex(idx).split('x')[1] | |
return salt+suffix | |
def hashCheck(hash,threshold): | |
return int(hash,16) < int(threshold,16) | |
def cap(args): | |
response = requests.get(f"https://ahashplace.herokuapp.com/?x={args['x']}&y={args['y']}",allow_redirects=True) | |
attrs = dict(parse.parse_qsl(response.url.split("?")[1])) | |
for i in attrs.items(): | |
print(i) | |
soup = BeautifulSoup(response.text,"html.parser") | |
threshold = soup.find(id="hash").text | |
print(threshold) | |
flavor = findFlavor(args) | |
query_string = parse.urlencode(args, quote_via=parse.quote_plus) | |
block = f"{query_string}&{flavor}=" | |
count = 0 | |
while True: | |
salt = hex(count).split('x')[1] | |
if hashCheck(hashlib.sha256((block+salt).encode()).hexdigest(),threshold): | |
break | |
count += 1 | |
response = requests.get(f"https://ahashplace.herokuapp.com/?"+block+salt,allow_redirects=True) | |
soup = BeautifulSoup(response.text,"html.parser") | |
print(soup.find(id="hash").text) | |
def grabOg(): | |
image_url = "https://i.imgur.com/WmHgHV6.png" | |
filename = "aHashPlaceBase.png" | |
r = requests.get(image_url, stream = True) | |
if r.status_code == 200: | |
r.raw.decode_content = True | |
with open(filename,'wb') as f: | |
shutil.copyfileobj(r.raw, f) | |
print('Image sucessfully Downloaded: ',filename) | |
else: | |
print('Image Couldn\'t be retreived') | |
try: | |
xPos = int(sys.argv[1]) | |
yPos = int(sys.argv[2]) | |
source = sys.argv[3] | |
scale = float(sys.argv[4]) | |
i = Image.open(source) | |
except: | |
xPos = 0 | |
yPos = 0 | |
grabOg() | |
source = "aHashPlaceBase.png" | |
scale = 1 | |
i = Image.open(source) | |
def paddedHex(n): | |
h = hex(n).split("x")[1] | |
return ("0"+h) if len(h) == 0 else h | |
def tupleToHex(t): | |
return "#"+paddedHex(t[0])+paddedHex(t[1])+paddedHex(t[2]) | |
resized = i.resize((int(i.width*scale),int(i.height*scale))) | |
data = resized.getdata() | |
width = resized.width | |
for n,pix in enumerate(data): | |
y = int(n/width) | |
x = int(n-width*y) | |
cap({"x":x+xPos,"y":y+yPos,"color":tupleToHex(pix)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment