-
Notifications
You must be signed in to change notification settings - Fork 1
/
hashacat.py
executable file
·85 lines (68 loc) · 1.99 KB
/
hashacat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!.//venv/bin/python
from flask import Flask, send_file, request, render_template
from flask.ext.jsonpify import jsonify
from corsSupport import crossdomain
from rateLimiting import rate_limit
import re
import os, os.path
import hashlib
import random
import base64
app = Flask(__name__)
def updateCatCount():
global catCount
catCount = len(os.walk('./static/cats/').next()[2])
pass
def verifyHash(hash):
return bool(re.search("^([a-f0-9]{40})$|^([a-f0-9]{32})$", hash))
@app.route('/cat/<hash>')
@crossdomain(origin='*')
@rate_limit(5, 3)
def returnCat(hash):
if verifyHash(hash):
catID = int(hash, 16) % catCount
if request.args.get('size') == 'small':
catURL = "http://cats.hashacat.com/small/" + str(catID) + ".gif"
else:
catURL = "http://cats.hashacat.com/" + str(catID) + ".jpg"
if request.args.get('format') == 'json':
return jsonify(cat=catURL)
else:
if request.args.get('size') == 'small':
catPath = 'static/cats/small/' + str(catID) + '.gif'
else:
catPath = 'static/cats/' + str(catID) + '.jpg'
return send_file(catPath)
else:
return "Bad hash!"
@app.route('/random')
@crossdomain(origin='*')
@rate_limit(5, 3)
def returnRandomCat():
hash = hashlib.sha1(str(random.random())).hexdigest()
catID = int(hash, 16) % catCount
cat_url = "http://cats.hashacat.com/" + str(catID) + ".jpg"
return render_template('random.html', cat_url=cat_url, hash=hash)
@app.route('/info')
def displayInfo():
return render_template('info.html')
@app.route('/randomHash')
@rate_limit(5, 3)
def getRandomHash():
hash = hashlib.sha1(str(random.random())).hexdigest()
return jsonify(hash=hash)
@app.route('/hash/<hashText>')
@rate_limit(5, 3)
def getHash(hashText):
try:
decoded = base64.b64decode(hashText)
hash = hashlib.sha1(str(decoded[:255])).hexdigest()
return jsonify(hash=hash)
except:
return "Couldn't hash that, is it base64?"
@app.route('/')
def displayIndex():
return render_template('mainPage.html')
if __name__ == '__main__':
app.run()
updateCatCount()