Skip to content

Commit

Permalink
Implemented password and otp generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-jiteshlalwani committed Jul 3, 2021
2 parents e240228 + ea7dde9 commit 83c186d
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 7 deletions.
2 changes: 2 additions & 0 deletions quantumcat/applications/generator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@


from quantumcat.applications.generator.random_number import RandomNumber
from quantumcat.applications.generator.password import Password
from quantumcat.applications.generator.otp import OTP
35 changes: 35 additions & 0 deletions quantumcat/applications/generator/otp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# (C) Copyright Artificial Brain 2021.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import requests
from quantumcat.utils import constants, ErrorMessages
from quantumcat.exceptions import OTPLengthError


class OTP:
def __init__(self):
self.length = 5

def generate(self):
ANU_QRNG_REQUEST_URL = constants.ANU_QRNG_URL + '?length=10&type=' + \
constants.UNIT16_TYPE
response = requests.get(ANU_QRNG_REQUEST_URL)
if response.status_code != 200:
return 'Something went wromg'
data = response.json()
otp = data['data']
for i in range(len(otp)):
if len(str(otp[i])) == self.length:
return otp[i]
36 changes: 36 additions & 0 deletions quantumcat/applications/generator/password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# (C) Copyright Artificial Brain 2021.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import requests
from quantumcat.utils import constants, ErrorMessages
from quantumcat.exceptions import PasswordLengthError


class Password:
def __init__(self, length):
self.length = length

def generate(self):
if not (4 < self.length <= 20):
raise PasswordLengthError(ErrorMessages.PASSWORD_LENGTH_INCORRECT)

ANU_QRNG_REQUEST_URL = constants.ANU_QRNG_URL + '?length=1&type=' + \
constants.HEX_TYPE + '&size=' + str(self.length)
response = requests.get(ANU_QRNG_REQUEST_URL)
if response.status_code != 200:
return 'Something went wromg'
data = response.json()
password = data['data'][0]
return password[0: self.length]
4 changes: 2 additions & 2 deletions quantumcat/circuit/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def get_operations(self):

def check_qubit_boundary(self, qubit):
if qubit > (self.qubits - 1):
raise CircuitError(ErrorMessages.qubit_out_of_bound)
raise CircuitError(ErrorMessages.QUBIT_OUT_OF_BOUND)

def draw_circuit(self, provider=providers.DEFAULT_PROVIDER):
self.check_and_convert(provider)
Expand Down Expand Up @@ -427,7 +427,7 @@ def execute(self, provider=providers.DEFAULT_PROVIDER,
simulator_name, repetitions, api)
elif self.provider == providers.IONQ_PROVIDER:
if api is None:
raise APIDetailsNotFoundError(ErrorMessages.ionq_api_details_not_provided)
raise APIDetailsNotFoundError(ErrorMessages.IONQ_API_DETAILS_NOT_PROVIDED)
return execute_circuit.on_ionq(self.converted_q_circuit,
default_target, repetitions, api, self.get_operations())

Expand Down
3 changes: 3 additions & 0 deletions quantumcat/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.


from quantumcat.exceptions.exception import QuantumCatError
from quantumcat.exceptions.circuit_error import CircuitError
from quantumcat.exceptions.install_error import InstallNotFoundError
from quantumcat.exceptions.api_error import APIDetailsNotFoundError
from quantumcat.exceptions.password_length import PasswordLengthError
from quantumcat.exceptions.otp_length import OTPLengthError
21 changes: 21 additions & 0 deletions quantumcat/exceptions/otp_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# (C) Copyright Artificial Brain 2021.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from quantumcat.exceptions import QuantumCatError


class OTPLengthError(QuantumCatError):
"""Base class for errors raised for api details not found."""

pass
21 changes: 21 additions & 0 deletions quantumcat/exceptions/password_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# (C) Copyright Artificial Brain 2021.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from quantumcat.exceptions import QuantumCatError


class PasswordLengthError(QuantumCatError):
"""Base class for errors raised for api details not found."""

pass
3 changes: 3 additions & 0 deletions quantumcat/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
PARAMS = 'params'
BINARY = 'binary'
DECIMAL = 'decimal'
ANU_QRNG_URL = 'https://qrng.anu.edu.au/API/jsonI.php'
HEX_TYPE = 'hex16'
UNIT16_TYPE = 'uint16'
13 changes: 8 additions & 5 deletions quantumcat/utils/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

qubit_out_of_bound = 'Qubit is out of bound.'
cbit_out_of_bound = 'Classical Bit is out of bound.'
qiskit_not_installed = 'Qiskit is not installed.'
api_details_not_provided = 'API Key is required for running on real quantum device.'
ionq_api_details_not_provided = 'API Key is required for running on IonQ.'
QUBIT_OUT_OF_BOUND = 'Qubit is out of bound.'
CBIT_OUT_OF_BOUND = 'Classical Bit is out of bound.'
QISKIT_NOT_INSTALLED = 'Qiskit is not installed.'
API_DETAILS_NOT_PROVIDED = 'API Key is required for running on real quantum device.'
IONQ_API_DETAILS_NOT_PROVIDED = 'API Key is required for running on IonQ.'
PASSWORD_LENGTH_INCORRECT = 'Password length should be between 5 and 20'
OTP_LENGTH_INCORRECT = 'OTP length should be either 4 or 5'

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
qiskit==0.26.2
cirq==0.11.0
amazon-braket-sdk==1.6.4
requests==2.25.1

0 comments on commit 83c186d

Please sign in to comment.