Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__/
raw_data/
restored_file/
encrypted/
files/
key/
uploads/
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Methodology

To achieve the above goal, the following methodology needs to be followed:</br>

1. Load the file on the server.</br>
2. Dividing the uploaded file into N parts.</br>
3. Encrypting all the parts of the file using any one of the selected algorithms (Algorithm is changed with every part in round robin fashion).</br>
Expand All @@ -13,27 +14,28 @@ To achieve the above goal, the following methodology needs to be followed:</br>
After the above 4 steps you will have a N files which are in encrypted form which are stored on the server and a key which is downloaded as public key for decrypting the file and downloading it.</br>

To restore the file, follow the following steps:</br>

1. Load the key on the server.</br>
2. Decrypt the keys of the algorithms.</br>
3. Decrypt all the N parts of the file using the same algorithms which were used to encrypt them.</br>
4. Combine all the N parts to form the original file and provide it to the user for downloading.</br>

# How to Run

**NOTE:** The project is based on Python 2.7.15 plateform running it on any other plateform might create some issues.</br>
**NOTE:** The project is based on Python 3.8.10 platform running it on any other platform might create some issues.</br>

Step 1: Install Requirements</br>
`pip install -r requirements.txt`</br>

Step 2: Run the application</br>
`python app.py`</br>
`python3 app.py`</br>

Step 3: Visit the localhost from your browser</br>

Step 4: Enjoy :)
[//]: <> (*IF YOU ENCOUNTER ANY BUGS OR FOR ANY SUGGESTIONS REGARDING THE IMPROVEMENT OF THE PROJECT FEEL FREE TO CONTACT ME :**)

[//]: <> (\*IF YOU ENCOUNTER ANY BUGS OR FOR ANY SUGGESTIONS REGARDING THE IMPROVEMENT OF THE PROJECT FEEL FREE TO CONTACT ME :\*\*)

**THE PROJECT HAS ENCOUNTERED A BUG BECAUSE OF THE CRYPTOGRAPHY LIBRARY BEING UPDATED. IF YOU ARE INTRESTED IN COLLABORATING TO IMPROVE THIS PROJECT FEEL FREE TO CONTACT ME :**

Shivang Srivastava - [email protected]<br/>
Shivang Srivastava - [email protected]<br/>
142 changes: 78 additions & 64 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from flask import Flask, request, redirect, url_for, render_template, send_from_directory, send_file
from flask import Flask, request, redirect, url_for, render_template, send_from_directory, send_file, flash
from werkzeug.utils import secure_filename
import tools
import divider as dv
Expand All @@ -17,95 +17,109 @@

#port = int(os.getenv('PORT', 8000))


def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


def start_encryption():
dv.divide()
tools.empty_folder('uploads')
enc.encrypter()
return render_template('success.html')
dv.divide()
tools.empty_folder('uploads')
enc.encrypter()
return render_template('success.html')


def start_decryption():
dec.decrypter()
tools.empty_folder('key')
rst.restore()
return render_template('restore_success.html')
dec.decrypter()
tools.empty_folder('key')
rst.restore()
return render_template('restore_success.html')


@app.route('/return-key/My_Key.pem')
@app.route('/return-key')
def return_key():
list_directory = tools.list_dir('key')
filename = './key/' + list_directory[0]
return send_file(filename, attachment_filename='My_Key.pem')
print("reached")
list_directory = tools.list_dir('key')
filename = './key/' + list_directory[0]
print(filename)
return send_file(filename, attachment_filename="My_Key.pem", as_attachment=True, cache_timeout=0)


@app.route('/return-file/')
def return_file():
list_directory = tools.list_dir('restored_file')
filename = './restored_file/' + list_directory[0]
print "****************************************"
print list_directory[0]
print "****************************************"
return send_file(filename, attachment_filename=list_directory[0], as_attachment=True)
list_directory = tools.list_dir('restored_file')
filename = './restored_file/' + list_directory[0]
print("****************************************")
print(list_directory[0])
print("****************************************")
return send_file(filename, attachment_filename=list_directory[0], as_attachment=True, cache_timeout=0)


@app.route('/download/')
def downloads():
return render_template('download.html')
return render_template('download.html')


@app.route('/upload')
def call_page_upload():
return render_template('upload.html')
return render_template('upload.html')


@app.route('/home')
def back_home():
tools.empty_folder('key')
tools.empty_folder('restored_file')
return render_template('index.html')
tools.empty_folder('key')
tools.empty_folder('restored_file')
return render_template('index.html')


@app.route('/')
def index():
return render_template('index.html')
return render_template('index.html')


@app.route('/data', methods=['GET', 'POST'])
def upload_file():
tools.empty_folder('uploads')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
return start_encryption()
return 'Invalid File Format !'

tools.empty_folder('uploads')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
return start_encryption()
return 'Invalid File Format !'


@app.route('/download_data', methods=['GET', 'POST'])
def upload_key():
tools.empty_folder('key')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename))
return start_decryption()
return 'Invalid File Format !'
tools.empty_folder('key')
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
flash('No selected file')
return 'NO FILE SELECTED'
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_KEY'], file.filename))
return start_decryption()
return 'Invalid File Format !'


if __name__ == '__main__':
app.run(host='127.0.0.1', port=8000, debug=True)
#app.run()
app.run(host='127.0.0.1', port=8000, debug=True)
# app.run()
Loading