-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
39 lines (31 loc) · 1.22 KB
/
app.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
from flask import Flask, request, send_from_directory
from flask import render_template as render
import cipher, decipher, os
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
CIPHERED_FILE_PATH = os.path.join(APP_ROOT, "files", "ciphers")
DECIPHERED_FILE_PATH = os.path.join(APP_ROOT, "files", "deciphers")
@app.route('/')
def index():
return render("index.html")
@app.route('/cipherFile')
def cipherFile():
return render("cipherFile.html")
@app.route('/decipherFile')
def decipherFile():
return render("decipherFile.html")
@app.route('/cipheredFile', methods=["POST"])
def cipheredFile():
plaintext = request.form['plainText']
cipher.cipher(plaintext)
return send_from_directory(directory=CIPHERED_FILE_PATH, filename="ciphered.txt", as_attachment=True)
@app.route('/decipheredFile', methods=["POST"])
def decipheredFile():
file = request.files['inputFile']
filename = file.filename
txtFile = os.path.join(APP_ROOT, "files", "ciphers", filename)
file.save(txtFile)
deciphered = decipher.decipher(txtFile)
return send_from_directory(directory=DECIPHERED_FILE_PATH, filename="deciphered.txt", as_attachment=True)
if __name__=='__main__':
app.run(debug=True)