├── qkd ├── qkd │ ├── __init__.py │ ├── __pycache__ │ │ ├── urls.cpython-37.pyc │ │ ├── wsgi.cpython-37.pyc │ │ ├── __init__.cpython-37.pyc │ │ └── settings.cpython-37.pyc │ ├── asgi.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py ├── accounts │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ ├── 0001_initial.cpython-37.pyc │ │ │ ├── 0002_profile.cpython-37.pyc │ │ │ ├── 0003_messages.cpython-37.pyc │ │ │ ├── 0002_auto_20200704_2324.cpython-37.pyc │ │ │ ├── 0003_auto_20200705_0056.cpython-37.pyc │ │ │ ├── 0004_auto_20200704_1345.cpython-37.pyc │ │ │ └── 0005_auto_20200704_1409.cpython-37.pyc │ │ ├── 0002_auto_20200704_2324.py │ │ ├── 0003_auto_20200705_0056.py │ │ └── 0001_initial.py │ ├── tests.py │ ├── apps.py │ ├── __pycache__ │ │ ├── eve.cpython-37.pyc │ │ ├── urls.cpython-37.pyc │ │ ├── admin.cpython-37.pyc │ │ ├── forms.cpython-37.pyc │ │ ├── models.cpython-37.pyc │ │ ├── qubit.cpython-37.pyc │ │ ├── sender.cpython-37.pyc │ │ ├── views.cpython-37.pyc │ │ ├── __init__.cpython-37.pyc │ │ ├── channel.cpython-37.pyc │ │ ├── quantum.cpython-37.pyc │ │ ├── receiver.cpython-37.pyc │ │ ├── decryption.cpython-37.pyc │ │ ├── encrypt_decrypt.cpython-37.pyc │ │ ├── quantum_channel.cpython-37.pyc │ │ └── classical_channel.cpython-37.pyc │ ├── classical_channel.py │ ├── admin.py │ ├── quantum_channel.py │ ├── eve.py │ ├── urls.py │ ├── quantum.py │ ├── qubit.py │ ├── models.py │ ├── encrypt_decrypt.py │ ├── static │ │ └── accounts │ │ │ └── index.css │ ├── receiver.py │ ├── sender.py │ ├── forms.py │ └── views.py ├── db.sqlite3 ├── media │ └── accounts │ │ └── images │ │ ├── com.jpg │ │ └── notebook.jpg ├── templates │ └── accounts │ │ ├── messagesdisplay.html │ │ ├── message.html │ │ ├── login.html │ │ ├── index.html │ │ ├── registration.html │ │ ├── chats.html │ │ └── chat.html └── manage.py └── README.md /qkd/qkd/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /qkd/accounts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /qkd/accounts/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /qkd/accounts/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /qkd/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/db.sqlite3 -------------------------------------------------------------------------------- /qkd/accounts/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AccountsConfig(AppConfig): 5 | name = 'accounts' 6 | -------------------------------------------------------------------------------- /qkd/media/accounts/images/com.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/media/accounts/images/com.jpg -------------------------------------------------------------------------------- /qkd/media/accounts/images/notebook.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/media/accounts/images/notebook.jpg -------------------------------------------------------------------------------- /qkd/qkd/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/qkd/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/qkd/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/qkd/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/eve.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/eve.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/qkd/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/qkd/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/qkd/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/qkd/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/forms.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/forms.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/qubit.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/qubit.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/sender.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/sender.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/channel.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/channel.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/quantum.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/quantum.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/receiver.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/receiver.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/decryption.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/decryption.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/encrypt_decrypt.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/encrypt_decrypt.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/quantum_channel.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/quantum_channel.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/__pycache__/classical_channel.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/__pycache__/classical_channel.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0002_profile.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0002_profile.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0003_messages.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0003_messages.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0002_auto_20200704_2324.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0002_auto_20200704_2324.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0003_auto_20200705_0056.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0003_auto_20200705_0056.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0004_auto_20200704_1345.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0004_auto_20200704_1345.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/accounts/migrations/__pycache__/0005_auto_20200704_1409.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aru71727/Secure-Communication-using-QKD/HEAD/qkd/accounts/migrations/__pycache__/0005_auto_20200704_1409.cpython-37.pyc -------------------------------------------------------------------------------- /qkd/templates/accounts/messagesdisplay.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Msgs 5 | 6 | 7 | 8 |

{{msg}}

9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /qkd/accounts/classical_channel.py: -------------------------------------------------------------------------------- 1 | from accounts.sender import receiver_basis,receiver_bits 2 | 3 | def exchange_basis(N,bob_basis): 4 | alice_basis = receiver_basis(N,bob_basis) 5 | return alice_basis 6 | 7 | def exchange_bits(bob_key,idx): 8 | alice_key = receiver_bits(bob_key,idx) 9 | return alice_key 10 | -------------------------------------------------------------------------------- /qkd/accounts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from.models import secret_keys,Profile,Messages,secret_keys_receiver 3 | 4 | # Register your models here. 5 | 6 | admin.site.register(secret_keys) 7 | admin.site.register(Profile) 8 | admin.site.register(Messages) 9 | admin.site.register(secret_keys_receiver) 10 | -------------------------------------------------------------------------------- /qkd/templates/accounts/message.html: -------------------------------------------------------------------------------- 1 | {% if messages %} 2 |
3 | 8 |
9 | 14 | {% endif %} -------------------------------------------------------------------------------- /qkd/accounts/quantum_channel.py: -------------------------------------------------------------------------------- 1 | from .qubit import qubit 2 | from .quantum import quantum_user 3 | from accounts.sender import sender 4 | from accounts.receiver import receiver 5 | from accounts.eve import Eve 6 | 7 | 8 | def QKD(N,s_idx,r_idx ,verbose = False,eve_present = False): 9 | 10 | alice_qubits = sender(N) 11 | if eve_present: 12 | alice_qubits = Eve(N,alice_qubits) 13 | status = receiver(N,alice_qubits,s_idx,r_idx) 14 | 15 | return status 16 | -------------------------------------------------------------------------------- /qkd/qkd/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for qkd project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'qkd.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /qkd/qkd/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for qkd project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'qkd.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /qkd/accounts/eve.py: -------------------------------------------------------------------------------- 1 | from .qubit import qubit 2 | from .quantum import quantum_user 3 | from random import randint 4 | 5 | def Eve(N,alice_qubits): 6 | eve_basis = generate_random_bits(N) 7 | eve = quantum_user("Eve") 8 | eve_bits = eve.receive(data=alice_qubits,basis=eve_basis) 9 | alice_qubits = eve.send(data=eve_bits,basis=eve_basis) 10 | return alice_qubits 11 | 12 | def generate_random_bits(N): 13 | aux = list() 14 | for i in range(N): 15 | aux.append(randint(0,1)) 16 | return aux 17 | 18 | 19 | -------------------------------------------------------------------------------- /qkd/accounts/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from django.urls import path,include 3 | from .views import registerview 4 | from .views import loginview,logoutview,chat,reviews,decrypt 5 | app_name='accounts' 6 | 7 | urlpatterns = [ 8 | path(r'register/', registerview, name="register"), 9 | path(r'login/', loginview, name="login"), 10 | path(r'logout/', logoutview, name="logout"), 11 | path(r'//chat/', chat, name="chat"), 12 | path(r'///reviews/', reviews, name="reviews"), 13 | path(r'////decrypt/', decrypt, name="decrypt"), 14 | 15 | 16 | 17 | ] -------------------------------------------------------------------------------- /qkd/accounts/migrations/0002_auto_20200704_2324.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-07-04 17:54 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('accounts', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RenameField( 14 | model_name='messages', 15 | old_name='msg_body', 16 | new_name='s_msg_body', 17 | ), 18 | migrations.AddField( 19 | model_name='messages', 20 | name='r_msg_body', 21 | field=models.CharField(default='', max_length=500), 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /qkd/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'qkd.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /qkd/accounts/migrations/0003_auto_20200705_0056.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-07-04 19:26 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('accounts', '0002_auto_20200704_2324'), 11 | ] 12 | 13 | operations = [ 14 | migrations.RemoveField( 15 | model_name='secret_keys_receiver', 16 | name='s_index', 17 | ), 18 | migrations.AddField( 19 | model_name='secret_keys', 20 | name='r_index', 21 | field=models.OneToOneField(default=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.secret_keys_receiver'), 22 | ), 23 | migrations.AlterField( 24 | model_name='messages', 25 | name='index', 26 | field=models.IntegerField(default=0, max_length=10), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /qkd/qkd/urls.py: -------------------------------------------------------------------------------- 1 | """qkd URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from accounts.views import func 18 | from django.urls import path,include 19 | from django.conf import settings 20 | from django.conf.urls.static import static 21 | 22 | urlpatterns = [ 23 | path('admin/', admin.site.urls), 24 | path(r'', func, name="home"), 25 | path(r'accounts/', include('accounts.urls', namespace="accounts")), 26 | ] 27 | 28 | urlpatterns = urlpatterns + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) -------------------------------------------------------------------------------- /qkd/accounts/quantum.py: -------------------------------------------------------------------------------- 1 | from .qubit import qubit 2 | class quantum_user(): 3 | def __init__(self,name): 4 | self.name = name 5 | def send(self,data,basis): 6 | """ 7 | Uso base computacional |0> y |1> para los estados horizontal y vertical. 8 | Uso base Hadamard |0> + |1> y |0> - |1> para los estados diagonales. 9 | 0 0 -> |0> 10 | 0 1 -> |1> 11 | 1 0 -> |0> + |1> 12 | 1 1 -> |0> - |1> 13 | """ 14 | assert len(data) == len(basis), "Basis and data must be the same length!" 15 | qubits = list() 16 | for i in range(len(data)): 17 | if not basis[i]: 18 | #Base computacional 19 | if not data[i]: 20 | qubits.append(qubit(0)) 21 | else: 22 | qubits.append(qubit(1)) 23 | else: 24 | #Base Hadamard 25 | if not data[i]: 26 | aux = qubit(0) 27 | else: 28 | aux = qubit(1) 29 | aux.hadamard() 30 | qubits.append(aux) 31 | return qubits 32 | def receive(self,data,basis): 33 | assert len(data) == len(basis), "Basis and data must be the same length!" 34 | bits = list() 35 | for i in range(len(data)): 36 | if not basis[i]: 37 | bits.append(data[i].measure()) 38 | else: 39 | data[i].hadamard() 40 | bits.append(data[i].measure()) 41 | return bits -------------------------------------------------------------------------------- /qkd/accounts/qubit.py: -------------------------------------------------------------------------------- 1 | from numpy import matrix 2 | from math import pow, sqrt 3 | from random import randint 4 | class qubit(): 5 | def __init__(self,initial_state): 6 | if initial_state: 7 | self.__state = matrix([[0],[1]]) 8 | else: 9 | self.__state = matrix([[1],[0]]) 10 | self.__measured = False 11 | self.__H = (1/sqrt(2))*matrix([[1,1],[1,-1]]) 12 | self.__X = matrix([[0,1],[1,0]]) 13 | def show(self): 14 | aux = "" 15 | if round(matrix([1,0])*self.__state,2): 16 | aux += "{0}|0>".format(str(round(matrix([1,0])*self.__state,2)) if round(matrix([1,0])*self.__state,2) != 1.0 else '') 17 | if round(matrix([0,1])*self.__state,2): 18 | if aux: 19 | aux += " + " 20 | aux += "{0}|1>".format(str(round(matrix([0,1])*self.__state,2)) if round(matrix([0,1])*self.__state,2) != 1.0 else '') 21 | return aux 22 | def measure(self): 23 | if self.__measured: 24 | raise Exception("Qubit already measured!") 25 | M = 1000000 26 | m = randint(0,M) 27 | self.__measured = True 28 | if m < round(pow(matrix([1,0])*self.__state,2),2)*M: 29 | return 0 30 | else: 31 | return 1 32 | def hadamard(self): 33 | if self.__measured: 34 | raise Exception("Qubit already measured!") 35 | self.__state = self.__H*self.__state 36 | def X(self): 37 | if self.__measured: 38 | raise Exception("Qubit already measured!") 39 | self.__state = self.__X*self.__state 40 | -------------------------------------------------------------------------------- /qkd/accounts/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | 4 | # Create your models here. 5 | 6 | class secret_keys_receiver(models.Model): 7 | receiver_key = models.CharField(max_length=1000) 8 | 9 | class secret_keys(models.Model): 10 | sender_key = models.CharField(max_length=1000) 11 | r_index = models.OneToOneField(secret_keys_receiver, on_delete=models.CASCADE,default=True) 12 | 13 | 14 | 15 | 16 | class Profile(models.Model): 17 | 18 | user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) 19 | address = models.CharField(max_length=30) 20 | mobile = models.CharField(max_length=13) 21 | gender = models.CharField(max_length=6) 22 | joined_date = models.DateTimeField(auto_now=True, auto_now_add=False, null=True) 23 | 24 | 25 | def __str__(self): 26 | return self.address 27 | 28 | def __unicode__(self): 29 | return self.address 30 | 31 | class Messages(models.Model): 32 | sender = models.CharField(max_length=30) 33 | receiver = models.CharField(max_length=30) 34 | s_msg_body = models.CharField(max_length=250) 35 | r_msg_body = models.CharField(max_length=500, default="") 36 | seen = models.BooleanField(default=False) 37 | date_time = models.DateTimeField(auto_now=False,auto_now_add=True, null=True) 38 | index = models.IntegerField(max_length=10,default=0) 39 | 40 | 41 | def __str__(self): 42 | return str(self.id) 43 | 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Secure-Communication-using-QKD 2 | 3 | The security of our critical infrastructure is threatened by the advent of future quantum computers, breaking asymmetric cryptography – an essential part of our secure communication architecture. Quantum key distribution (QKD) remedies this weakness by providing a long term secure solution, safe against attacks from quantum computers. 4 | 5 | There are indeed many aspects to cryptography, and many different cryptographic tasks that one may consider. Likely the 6 | first cryptographic task that comes to mind is private communication: Alice and Bob wish to 7 | communicate, and they do not want an eavesdropper (Eve) to learn any information about their 8 | communication. There are many other cryptographic tasks or protocols one may consider, such as 9 | message authentication, digital signatures, and voting schemes. Often these tasks are broken down 10 | into more primitive operations, such as bit-commitment and oblivious transfer. 11 | 12 | Quantum key distribution 13 | The aim of quantum key distribution is to allow Alice and Bob to generate a secure private key 14 | that can be used for the one-time pad without having to meet privately. They will be able to 15 | accomplish this task by using quantum information. There are a few different schemes for doing 16 | this, and among them one of them is: 17 | BB84,which is Easy to implement, relatively hard to prove security. 18 | 19 | 20 | For detailed explanation: 21 | https://arxiv.org/ftp/arxiv/papers/1409/1409.1452.pdf 22 | -------------------------------------------------------------------------------- /qkd/accounts/encrypt_decrypt.py: -------------------------------------------------------------------------------- 1 | import base64 2 | from cryptography.fernet import Fernet 3 | from .models import secret_keys,secret_keys_receiver,Messages 4 | 5 | def encryption(id,msg): 6 | key = secret_keys.objects.filter(id = id) 7 | key = key[0].sender_key 8 | 9 | # encoded_message = msg.encode() 10 | # f = Fernet(key) 11 | # encrypted_message = f.encrypt(encoded_message) 12 | 13 | # print(encrypted_message) 14 | encrypted_message = base64.b64encode((msg).encode('utf-8')) 15 | # encrypted_message = b64encode(msg) 16 | 17 | return encrypted_message 18 | 19 | def decryption(id,msg): 20 | key = secret_keys_receiver.objects.filter(id = id) 21 | key = key[0].receiver_key 22 | # encoded_message = msg.encode() 23 | # f = Fernet(key) 24 | # encrypted_message = f.encrypt(encoded_message) 25 | 26 | # print(encrypted_message) 27 | msg = (base64.b64decode(msg)).decode('utf-8') 28 | # encrypted_message = b64encode(msg) 29 | 30 | return msg 31 | 32 | def s_key(s_idx): 33 | secret_key = secret_keys.objects.filter(id= s_idx) 34 | secret_key= secret_key[0].sender_key 35 | return secret_key 36 | 37 | def r_key(r_idx): 38 | secret_key = secret_keys_receiver.objects.filter(id= r_idx) 39 | secret_key= secret_key[0].receiver_key 40 | return secret_key 41 | 42 | def decryptin(id): 43 | print("asdsssfssssssss") 44 | print(id) 45 | for i in id: 46 | 47 | # secret_key = Messages.objects.filter(id= i) 48 | # secret_key = secret_key[0].s_msg_body 49 | secret_key = i.s_msg_body 50 | print(secret_key) 51 | print("abc") 52 | return secret_key 53 | 54 | 55 | -------------------------------------------------------------------------------- /qkd/accounts/static/accounts/index.css: -------------------------------------------------------------------------------- 1 | *{ 2 | margin-top: 0px; 3 | padding: 0px; 4 | 5 | } 6 | #div21{ 7 | background-image: url("/media/accounts/images/com.jpg"); 8 | background-repeat: no-repeat; 9 | background-size: 1350px 375px; 10 | /*background-position: right top;*/ 11 | } 12 | #wrapper{ 13 | margin-top: 0px; 14 | height: auto; 15 | width: 1000px; 16 | } 17 | #first{ 18 | position: absolute; 19 | height: 160px; 20 | width: 1000px; 21 | background-color: #28004d; 22 | text-align: center; 23 | color: white; 24 | } 25 | 26 | #menu{ 27 | height: 60px; 28 | /* background-color: black;*/ 29 | width: 100%; 30 | 31 | 32 | } 33 | 34 | #menu4 35 | { 36 | height:30px; 37 | border:1px solid black; 38 | width:1000px; 39 | margin-top: 20px; 40 | 41 | } 42 | #menu4 ul 43 | { 44 | list-style-type:none; 45 | } 46 | #menu4 ul li 47 | { 48 | display:inline; 49 | padding:10px; 50 | margin-left:18px; 51 | margin-top: 15px; 52 | } 53 | #menu4 ul li a 54 | { 55 | color:white; 56 | text-decoration:none; 57 | font-weight:bold; 58 | } 59 | #menu4 ul li a:hover 60 | { 61 | color:yellow; 62 | border-top:1px solid yellow; 63 | border-bottom:1px solid yellow; 64 | } 65 | 66 | 67 | 68 | 69 | 70 | 71 | img{ 72 | width:100%; 73 | height:100%; 74 | } 75 | 76 | #div1 77 | { 78 | margin-top:203px; 79 | width:1000px; 80 | height:400px; 81 | position: absolute; 82 | 83 | } 84 | #footer{ 85 | height: 50px; 86 | width: 1350px; 87 | background-color: #28004d; 88 | position: absolute; 89 | margin-bottom: : 0px; 90 | font-family: Times new roman; 91 | color: #ffffff; 92 | padding: 20px; 93 | 94 | } -------------------------------------------------------------------------------- /qkd/accounts/receiver.py: -------------------------------------------------------------------------------- 1 | from .qubit import qubit 2 | from .quantum import quantum_user 3 | from random import randint 4 | from .models import secret_keys_receiver,Messages 5 | from accounts.classical_channel import exchange_bits, exchange_basis 6 | 7 | 8 | receiver_bits = list() 9 | receiver_basis = list() 10 | bob_key = list() 11 | 12 | def receiver(N,alice_qubits,s_idx,r_idx): 13 | bob_basis = generate_random_bits(N) 14 | bob = quantum_user("Bob") 15 | bob_bits = bob.receive(data = alice_qubits,basis = bob_basis) 16 | receiver_basis = bob_basis 17 | receiver_bits = bob_bits 18 | sender_basis = exchange_basis(N,receiver_basis) 19 | bob_key.clear() 20 | for i in range(N): 21 | if sender_basis[i] == receiver_basis[i]: 22 | bob_key.append(receiver_bits[i]) 23 | 24 | 25 | alice_key = exchange_bits(bob_key,s_idx) 26 | if alice_key != bob_key: 27 | key = False 28 | length = None 29 | # print ("Encription key mismatch, eve is present.") 30 | else: 31 | key = True 32 | length = len(bob_key) 33 | #print ("Successfully exchanged key!") 34 | 35 | key_length = 128 36 | key_value = (hex(int(''.join([ str(i) for i in alice_key]), 2))[2:key_length + 2]) 37 | secret_key = secret_keys_receiver.objects.filter(id = r_idx) 38 | secret_key = secret_key[0].receiver_key+key_value 39 | secret_keys_receiver.objects.filter(id = r_idx).update(receiver_key = secret_key) 40 | print ("Bob Key : {} " .format(bob_key)) 41 | return key 42 | 43 | 44 | def generate_random_bits(N): 45 | aux = list() 46 | for i in range(N): 47 | aux.append(randint(0,1)) 48 | return aux 49 | 50 | 51 | # def decryption(info,msg): 52 | # info.update(r_msg_body = msg) 53 | # return 54 | 55 | def receiver_msg(info,msg): 56 | print(info) 57 | for i in info : 58 | idx = i.id 59 | Messages.objects.filter(id=idx).update(r_msg_body = msg, seen = True) 60 | print("xyz") 61 | return 62 | 63 | def receive_msg(info,msg): 64 | 65 | Messages.objects.filter(id=info).update(r_msg_body = msg, seen = True) 66 | 67 | return 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /qkd/accounts/sender.py: -------------------------------------------------------------------------------- 1 | from .qubit import qubit 2 | from .quantum import quantum_user 3 | from random import randint 4 | from .models import secret_keys,Messages 5 | # # from accounts.channel import encrypt_decrypt 6 | # from accounts.channel import encrypt_decrypt 7 | 8 | sender_basis = list() 9 | sender_bits = list() 10 | alice_key = list() 11 | alice_basis = list() 12 | 13 | 14 | def sender(N): 15 | alice_basis = generate_random_bits(N) 16 | alice_bits = generate_random_bits(N) 17 | alice = quantum_user("Alice") 18 | alice_qubits = alice.send(data=alice_bits,basis=alice_basis) 19 | sender_basis.clear() 20 | sender_bits.clear() 21 | for i in range(N): 22 | sender_basis.append(alice_basis[i]) 23 | sender_bits.append(alice_bits[i]) 24 | return alice_qubits 25 | 26 | def receiver_basis(N,receiver_basis): 27 | alice_key.clear() 28 | for i in range(N): 29 | if sender_basis[i] == receiver_basis[i]: 30 | alice_key.append(sender_bits[i]) 31 | return sender_basis 32 | 33 | 34 | def receiver_bits(bob_key,s_idx): 35 | if alice_key != bob_key: 36 | key = False 37 | length = None 38 | print ("Encription key mismatch, eve is present.") 39 | else: 40 | key = True 41 | length = len(alice_key) 42 | print ("Successfully exchanged key!") 43 | print ("Key Length: " + str(length)) 44 | 45 | key_length = 128 46 | key_value = (hex(int(''.join([ str(i) for i in alice_key]), 2))[2:key_length + 2]) 47 | secret_key = secret_keys.objects.filter(id= s_idx) 48 | secret_key = secret_key[0].sender_key+key_value 49 | secret_keys.objects.filter(id= s_idx).update(sender_key = secret_key) 50 | print ("Alice Key : {} " .format(alice_key)) 51 | return alice_key 52 | 53 | 54 | def generate_random_bits(N): 55 | aux = list() 56 | for i in range(N): 57 | aux.append(randint(0,1)) 58 | return aux 59 | 60 | # def encryption(info,msg): 61 | # info.update(s_msg_body = msg) 62 | # encrypt_decrypt(info,msg) 63 | # return 64 | 65 | def sender_msg(info,msg): 66 | Messages.objects.filter(id=info).update(s_msg_body = msg) 67 | # encrypt_decrypt(info,msg) 68 | return 69 | 70 | 71 | -------------------------------------------------------------------------------- /qkd/accounts/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-07-04 09:23 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='secret_keys', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('sender_key', models.CharField(max_length=1000)), 22 | ], 23 | ), 24 | migrations.CreateModel( 25 | name='secret_keys_receiver', 26 | fields=[ 27 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 28 | ('receiver_key', models.CharField(max_length=1000)), 29 | ('s_index', models.OneToOneField(default=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.secret_keys')), 30 | ], 31 | ), 32 | migrations.CreateModel( 33 | name='Profile', 34 | fields=[ 35 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 36 | ('address', models.CharField(max_length=30)), 37 | ('mobile', models.CharField(max_length=13)), 38 | ('gender', models.CharField(max_length=6)), 39 | ('joined_date', models.DateTimeField(auto_now=True, null=True)), 40 | ('user', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 41 | ], 42 | ), 43 | migrations.CreateModel( 44 | name='Messages', 45 | fields=[ 46 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 47 | ('sender', models.CharField(max_length=30)), 48 | ('receiver', models.CharField(max_length=30)), 49 | ('msg_body', models.CharField(max_length=250)), 50 | ('seen', models.BooleanField(default=False)), 51 | ('date_time', models.DateTimeField(auto_now_add=True, null=True)), 52 | ('index', models.OneToOneField(blank=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.secret_keys')), 53 | ], 54 | ), 55 | ] 56 | -------------------------------------------------------------------------------- /qkd/templates/accounts/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | 24 | 25 |
26 | 27 |

L O G I N

28 | 29 | 30 |
31 | 32 | 33 | 34 | 129 | 130 | 131 |
132 |
"Communication – the human connection"
133 |
134 | 135 |
136 |
137 | {% csrf_token %} 138 | {{form.as_p|safe}} 139 |
140 | 141 |
142 | 143 |
144 |
145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /qkd/templates/accounts/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% load static %} 6 | 7 | Secure Communication Using Quantum Key Distribution 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 | 17 |
18 | {% if user.is_authenticated %} 19 |

HELLO!!   {{ user.first_name}}

20 |

Communication – the human connection

21 | {% else %} 22 |

Secure Communication Using Quantum Key Distribution

23 |

Communication – the human connection

24 | {% endif %} 25 |
26 |
27 | 45 | 46 | 47 | 48 |
49 |
50 |
51 | {% if user.is_authenticated %} 52 | 53 | 54 | {% for i in profiles %} 55 | 56 | 58 |
59 | {% endfor %} 60 | 61 |
62 | 63 | {% else %} 64 | 65 | {% endif %} 66 |
67 |
68 |
69 | 70 | 71 | 72 | 80 | 81 | 82 |
83 | 84 | -------------------------------------------------------------------------------- /qkd/templates/accounts/registration.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | 24 | 25 |
26 | 27 |

R E G I S T E R

28 | 29 | 30 |
31 | 32 | 33 | 34 | 128 | 129 | 130 | 131 |
Communication – the human connection"
132 |
133 |
134 |
{% csrf_token %} 135 | 136 | {{ form.as_p }} 137 |
138 |

139 |

140 |
141 | 142 | 143 |
144 | 145 |
146 |
147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /qkd/qkd/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for qkd project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.8. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'nry0nkzzcnj()7fg=l!3-3e^@8x$@0wfvn3zp$*(!0ft)eaedj' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'accounts', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'qkd.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'qkd.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | MEDIA_ROOT=os.path.join(BASE_DIR,'media') 123 | MEDIA_URL='/media/' 124 | -------------------------------------------------------------------------------- /qkd/templates/accounts/chats.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% load static %} 6 | 7 | NIT REVIEW SYSTEM 8 | 9 | 10 | 11 | 12 |
13 |
14 | 15 | 16 |
17 | {% if user.is_authenticated %} 18 |

HELLO!!   {{ user.first_name}}

19 |

Rate your college today!

20 | {% else %} 21 |

NIT REVIEWS

22 |

Rate your college today!

23 | {% endif %} 24 |
25 | 26 | 45 |
46 | 47 | 48 |
49 |
50 |
51 | {% if user.is_authenticated %} 52 | 53 | 54 | {% for i in profiles %} 55 | 56 | 58 |
59 | {% endfor %} 60 | 61 |
62 | 63 | {% else %} 64 | 65 | {% endif %} 66 |
67 |
68 |

{{ r_name}}

69 | 70 | {{r_msg.r_msg_body}} 71 | 72 | {% if r_seen == True %} 73 | Decrypt Message 74 | {% endif %} 75 | {% if seen == False %} 76 | {% if add == 0 %} 77 |


78 |
79 | Message : {{msg.s_msg_body}}

80 | 81 |
{% csrf_token %} 82 |

Write Message:

83 | 84 | 85 |
86 | 87 | 88 | 89 | {% else %} 90 | 91 |
{% csrf_token %} 92 |

Write Message:

93 | 94 | 95 |
96 | {% endif %} 97 | {% else %} 98 |


99 |
100 | Message : {{msg.s_msg_body}} 101 |

102 |

Message Not Seen Yet!!!

103 | {% endif %} 104 | 105 |
106 |
107 | 108 | 109 | 110 | 123 | 124 | 125 |
126 | 127 | -------------------------------------------------------------------------------- /qkd/accounts/forms.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth import authenticate 2 | from django.contrib.auth.models import User 3 | from django import forms 4 | from .models import Profile 5 | 6 | GENDER_CHOICES = [('Male','Male'), ('Female','Female'), ('Others','Others')] 7 | 8 | class RegistrationForm(forms.Form): 9 | 10 | first_name = forms.CharField(label="", widget=forms.TextInput(attrs={'autofocus':'on', 'autocomplete':'off', 'class':'form-control', 'placeholder':'First Name'})) 11 | last_name = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Surname'})) 12 | # reg = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Registration Number'})) 13 | #dob = forms.DateField(label="Date of birth", widget=forms.DateInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'YYYY-MM-DD'})) 14 | #gender = forms.CharField(label='Gender', widget=forms.RadioSelect(choices=GENDER_CHOICES, attrs={'class':'custom-control-inline'})) 15 | gender= forms.CharField(label='Gender', widget=forms.Select(choices=GENDER_CHOICES)) 16 | address = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'address'})) 17 | # college= forms.CharField(label='College', widget=forms.Select(choices=COLLEGE_CHOICES)) 18 | mobile = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Mobile Number'})) 19 | email = forms.CharField(label="", widget=forms.EmailInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Email address'})) 20 | username = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Username'})) 21 | password = forms.CharField(label="", widget=forms.PasswordInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Your Password'})) 22 | cpassword = forms.CharField(label="", widget=forms.PasswordInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Confirm Password'})) 23 | 24 | def clean_email(self): 25 | email = self.cleaned_data.get("email") 26 | if len(User.objects.filter(email=email)): 27 | raise forms.ValidationError("Email Already Registered") 28 | 29 | return email 30 | 31 | 32 | def clean_mobile(self): 33 | mobile = self.cleaned_data.get("mobile") 34 | try: 35 | a = int(mobile) 36 | except: 37 | raise forms.ValidationError("Incorrect mobile number") 38 | if len(mobile)!=10: 39 | raise forms.ValidationError("Incorrect mobile number") 40 | elif len(Profile.objects.filter(mobile=mobile)): 41 | raise forms.ValidationError("Mobile Already Registered") 42 | 43 | return mobile 44 | 45 | def clean_username(self): 46 | username = self.cleaned_data.get("username") 47 | if len(User.objects.filter(username=username)): 48 | raise forms.ValidationError("Username already has been taken") 49 | 50 | return username 51 | 52 | def clean_password(self): 53 | password = self.cleaned_data.get("password") 54 | if len(password)<6: 55 | raise forms.ValidationError("Password must be at least 6 characters") 56 | 57 | return password 58 | 59 | def clean_cpassword(self): 60 | password = self.cleaned_data.get("password") 61 | cpassword = self.cleaned_data.get("cpassword") 62 | if password!=cpassword: 63 | raise forms.ValidationError("Passwords must match") 64 | 65 | return password 66 | 67 | 68 | class LoginForm(forms.Form): 69 | username = forms.CharField(label="", widget=forms.TextInput(attrs={'autocomplete':'off','autofocus':'on','class':'form-control', 'placeholder':'Username'})) 70 | password = forms.CharField(label="", widget=forms.PasswordInput(attrs={'autocomplete':'off','class':'form-control', 'placeholder':'Password'})) 71 | 72 | def clean_username(self): 73 | username = self.cleaned_data.get("username") 74 | if len(User.objects.filter(username=username))==0: 75 | raise forms.ValidationError("Username does not exist") 76 | 77 | return username 78 | 79 | def clean_password(self): 80 | username = self.cleaned_data.get("username") 81 | password = self.cleaned_data.get("password") 82 | user = authenticate(username=username, password=password) 83 | if user is None: 84 | raise forms.ValidationError("Wrong Username or Password") 85 | return password 86 | -------------------------------------------------------------------------------- /qkd/templates/accounts/chat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% load static %} 6 | 7 | Secure Communication Using Quantum Key Distribution 8 | 9 | 10 | 11 | 12 |
13 | 14 |
15 | 16 | 17 |
18 | {% if user.is_authenticated %} 19 |

HELLO!!   {{ user.first_name}}

20 |

Communication – the human connection

21 | {% else %} 22 |

Secure Communication Using Quantum Key Distribution

23 |

Communication – the human connection

24 | {% endif %} 25 |
26 |
27 | 45 | 46 | 47 | 48 |
49 |
50 | 51 | {% if user.is_authenticated %} 52 | 53 | 54 | {% for i in profiles %} 55 | 56 | 58 |
59 | {% endfor %} 60 | 61 |
62 | 63 | {% else %} 64 | 65 | {% endif %} 66 | 67 |
68 |
69 |

70 |

{{ r_name}}


71 | 72 | {{r_msg.r_msg_body}}     73 | 74 | {% if r_seen == True %} 75 | 76 | Decrypt Message 77 | {% endif %} 78 | {% if seen == False %} 79 | {% if add == 0 %} 80 |


81 |
82 | Message : {{msg.s_msg_body}}

83 | 84 |
{% csrf_token %} 85 |

Write Message:

86 | 87 | 88 |
89 | 90 | 91 | 92 | {% else %} 93 | 94 |
{% csrf_token %} 95 |

Write Message:

96 | 97 | 98 |
99 | {% endif %} 100 | {% else %} 101 |


102 |
103 | Message : {{msg.s_msg_body}} 104 |

105 |

Message Not Seen Yet!!!

106 | {% endif %} 107 | 108 | 109 |
110 |
111 | 112 | 113 | 114 | 122 | 123 | 124 |
125 | 126 | -------------------------------------------------------------------------------- /qkd/accounts/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render,redirect 2 | import time 3 | from numpy import matrix 4 | from math import pow, sqrt 5 | from random import randint 6 | import sys, argparse 7 | from django.urls import reverse 8 | from accounts.quantum_channel import * 9 | from .models import secret_keys,secret_keys_receiver,Messages 10 | from .models import Profile 11 | from .forms import RegistrationForm,LoginForm 12 | from django.contrib.auth.models import User 13 | from django.contrib import messages 14 | from django.contrib.auth.decorators import login_required 15 | from django.http import HttpResponseRedirect,HttpResponse 16 | from accounts.sender import sender_msg 17 | from accounts.receiver import receiver_msg,receive_msg 18 | from accounts.encrypt_decrypt import * 19 | 20 | 21 | from django.contrib.auth import ( 22 | 23 | authenticate, 24 | login, 25 | logout 26 | 27 | ) 28 | 29 | def loginview(request): 30 | form = LoginForm(request.POST or None) 31 | if request.method =="POST": 32 | if form.is_valid(): 33 | username = form.cleaned_data.get("username") 34 | password = form.cleaned_data.get("password") 35 | print(username,password) 36 | user = authenticate(username=username, password=password) 37 | login(request, user) 38 | return HttpResponseRedirect(reverse("home")) 39 | 40 | context = { 41 | 'form':form 42 | } 43 | return render(request, 'accounts/login.html', context) 44 | 45 | 46 | @login_required 47 | def logoutview(request): 48 | logout(request) 49 | return HttpResponseRedirect(reverse('home')) 50 | 51 | 52 | 53 | 54 | def registerview(request): 55 | form = RegistrationForm(request.POST or None) 56 | 57 | if request.method=="POST": 58 | 59 | if form.is_valid(): 60 | first_name = form.cleaned_data.get('first_name') 61 | last_name= form.cleaned_data.get('last_name') 62 | address = form.cleaned_data.get("address") 63 | mobile = form.cleaned_data.get("mobile") 64 | gender = form.cleaned_data.get("gender") 65 | email = form.cleaned_data.get('email') 66 | username = form.cleaned_data.get("username") 67 | password = form.cleaned_data.get('password ') 68 | cpassword = form.cleaned_data.get('cpassword ') 69 | 70 | user, create = User.objects.get_or_create( 71 | 72 | first_name=first_name, 73 | last_name=last_name, 74 | username=username, 75 | email=email, 76 | 77 | ) 78 | user.set_password(form.cleaned_data['password']) 79 | user.save() 80 | 81 | 82 | pro = Profile(mobile=mobile, address = address , gender=gender, user=user ) 83 | pro.save() 84 | 85 | messages.success(request, "Successfully Saved") 86 | context={ 87 | "msg":"Successfully Registered!!" 88 | } 89 | 90 | return render(request,'accounts/messagesdisplay.html',context) 91 | context = { 92 | 'form':form, 93 | } 94 | return render(request, 'accounts/registration.html', context) 95 | 96 | 97 | 98 | 99 | 100 | def func(request): 101 | profiles = Profile.objects.all() 102 | return render(request,'accounts/index.html',{'profiles': profiles }) 103 | 104 | 105 | 106 | 107 | 108 | def chat(request,s_idx,r_idx): 109 | profiles = Profile.objects.all() 110 | # print(int(s_idx)) 111 | # print(int(r_idx)) 112 | # print(profiles) 113 | 114 | sender = Profile.objects.get(user=s_idx) 115 | # print(sender) 116 | receiver = Profile.objects.get(id=r_idx) 117 | # print(receiver) 118 | receiver = receiver.user 119 | sender = sender.user 120 | seen = False 121 | add = 0 122 | msg = Messages.objects.filter(sender = sender , receiver = receiver) 123 | r_msg = Messages.objects.filter(sender = receiver , receiver = sender) 124 | 125 | r_name = receiver 126 | r_seen = False 127 | r_ex = 0 128 | if len(r_msg) != 0: 129 | r_seen = r_msg[0].seen 130 | r_msg = r_msg[0] 131 | r_ex = 1 132 | 133 | if len(msg) == 0: 134 | add = 1 135 | else: 136 | msg = msg[0] 137 | seen = msg.seen 138 | # print(seen) 139 | # print(add) 140 | # print(msg.sender) 141 | pro = list() 142 | for i in profiles: 143 | if i.user != sender: 144 | pro.append(i) 145 | 146 | params = {'profiles':pro,'msg': msg,'add':add,'seen':seen,'idx':r_idx,'r_name':r_name,'r_msg':r_msg,'r_seen':r_seen,'r_ex':r_ex} 147 | 148 | return render(request,'accounts/chat.html',params) 149 | 150 | 151 | 152 | 153 | 154 | 155 | def reviews(request,id,idx,add): 156 | id=int(id) 157 | # print(id) 158 | # print(int(idx)) 159 | if request.method == "POST": 160 | msg = request.POST.get("message") 161 | print(msg) 162 | 163 | 164 | ret = list() 165 | N = 72 166 | key = secret_keys_receiver(receiver_key = "" ) 167 | key.save() 168 | r_idx = key.id 169 | key = secret_keys(sender_key = "" ,r_index=key) 170 | key.save() 171 | s_idx = key.id 172 | 173 | 174 | 175 | for i in range (N): 176 | print ("############# {0} #############".format(str(i))) 177 | ret.append(QKD(16,s_idx,r_idx,verbose = True ,eve_present = True)) 178 | 179 | print ("###############################".format(str(i))) 180 | t = "{0:.2f}".format(float(ret.count(True))*100.0/float(N)) 181 | u = "{0:.2f}".format(float(ret.count(False))*100.0/float(N)) 182 | # print ("True: {0} <{1}%>".format(ret.count(True),str(t))) 183 | # print ("False: {0} <{1}%>".format(ret.count(False),str(u))) 184 | 185 | print("Exchanged Secret keys") 186 | key = s_key(s_idx) 187 | print("Sender's secret key") 188 | print(key) 189 | key = r_key(r_idx) 190 | print("Receiver's secret key") 191 | print(key) 192 | sender = Profile.objects.get(user=id) 193 | # print(sender.user) 194 | receiver = Profile.objects.get(id=idx) 195 | # print(receiver.user) 196 | sender = sender.user 197 | receiver = receiver.user 198 | 199 | add = int(add) 200 | # print(type(s_idx)) 201 | 202 | if add == 1: 203 | info = Messages(sender = sender, receiver = receiver, s_msg_body = "",r_msg_body="", seen = False,index = s_idx) 204 | info.save() 205 | i = info.id 206 | sender_msg(i,msg) 207 | 208 | else: 209 | 210 | info = Messages.objects.filter(sender = sender , receiver = receiver).update( s_msg_body = "",r_msg_body="",seen = False, index = s_idx) 211 | 212 | i = info 213 | 214 | sender_msg(i,msg) 215 | print("Message to send :") 216 | print(msg) 217 | msg = encryption(s_idx,msg) 218 | print("Encrypted Msg : ") 219 | print(msg) 220 | 221 | receive_msg(i,msg) 222 | info = Messages.objects.filter(sender = sender , receiver = receiver).update(seen = True) 223 | 224 | msg = decryption(r_idx,msg) 225 | print("Decrypted Message :") 226 | print(msg) 227 | 228 | return redirect('accounts:chat', s_idx= id, r_idx = idx) 229 | 230 | 231 | 232 | 233 | def decrypt(request,id,idx,info,r_idx): 234 | 235 | info = Messages.objects.filter(id=info) 236 | print(info) 237 | 238 | print("hgsahgas") 239 | msg = decryptin(info) 240 | print(msg) 241 | receiver_msg(info,msg) 242 | for i in info: 243 | xyz = i.id 244 | Messages.objects.filter(id=xyz).update(seen = False) 245 | return redirect('accounts:chat', s_idx= id, r_idx = idx) 246 | 247 | --------------------------------------------------------------------------------