├── 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 |
4 | {% for message in messages %}
5 | - {{ message }}
6 | {% endfor %}
7 |
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 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |