-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
104 lines (90 loc) · 3.15 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#File app.py
from flask import Flask, render_template, request, jsonify
import cipher
app = Flask(__name__, static_folder="static/")
@app.route('/')
@app.route('/home/')
def home():
return render_template('encryption.html')
@app.route('/about/')
def about():
return render_template('about.html')
@app.route('/encrypt/caesar/', methods= ['POST'])
def caeser():
pt = request.form["plaintext"].lower()
key = request.form["key"]
ct = cipher.CCencrypt(pt,int(key))
if ct:
return jsonify({'cipher': ct})
return jsonify({'error' : 'Something went wrong'})
@app.route('/encrypt/multiplicative/', methods= ['POST'])
def multiplicative():
pt = request.form["plaintext"].lower()
key = request.form["key"]
ct = cipher.multiplicative(pt, int(key))
if ct:
return jsonify({'cipher': ct})
return jsonify({'error' : 'Something went wrong'})
@app.route('/encrypt/affine/', methods= ['POST'])
def affine():
pt = request.form["plaintext"]
multkey = request.form["affine_key1"]
addkey = request.form["affine_key2"]
ct = cipher.affine(pt,int(multkey),int(addkey))
if ct:
return jsonify({'cipher': ct})
return jsonify({'error' : 'Something went wrong'})
@app.route('/encrypt/vigenere/', methods= ['POST'])
def vigenere():
pt = request.form["plaintext"]
keyword = request.form["key"]
print(pt,keyword)
ct = cipher.vigenere_encrypt(pt,keyword)
if ct:
return jsonify({'cipher': ct})
return jsonify({'error' : 'Something went wrong'})
@app.route('/encrypt/autokey/',methods=['POST'])
def autokey():
pt = request.form['plaintext']
key = request.form['key']
ct = cipher.autokey_encrypt(pt, int(key))
if ct:
return jsonify({'cipher': ct})
return jsonify({'error':'Something went wrong'})
@app.route('/encrypt/playfair/',methods=['POST'])
def playfair():
pt = request.form['plaintext']
key = request.form['key']
msg,ct,key_matrix = cipher.playfair(pt,key)
if ct:
return jsonify({'msg':msg,'cipher': ct,'key_matrix':key_matrix})
return jsonify({'error':'Something went wrong'})
@app.route('/encrypt/keylesstrans/',methods=['POST'])
def keyless_transposition():
pt = request.form['plaintext']
block_size = request.form['block']
msg,ct = cipher.keyless_transposition(pt,int(block_size))
if ct:
return jsonify({'msg': msg ,'cipher': ct})
return jsonify({'error':'Something went wrong'})
@app.route('/encrypt/coltrans/',methods=['POST'])
def col_transposition():
pt = request.form['plaintext']
key = request.form['key']
error,msg,ct = cipher.columnar_transposition(pt,key)
if ct:
return jsonify({'code':200 ,'msg': msg ,'cipher': ct})
return jsonify({'code':400,'error': error})
@app.route('/decrypt/',methods=['GET'])
def decrypt():
return render_template('decryption.html')
@app.route('/decrypt/caesar/', methods=['POST'])
def caesar():
ct = request.form["cipher"].lower()
key = request.form["key"]
pt = cipher.CCdecrypt(ct,int(key))
if ct:
return jsonify({'plaintext': pt})
return jsonify({'error' : 'Something went wrong'})
if __name__ == '__main__':
app.run(debug=True)