Skip to content

Commit

Permalink
Merge pull request #101 from KOSASIH/deepsource-transform-928e6e5e
Browse files Browse the repository at this point in the history
style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf
  • Loading branch information
KOSASIH authored May 10, 2024
2 parents 93f3515 + 0caad04 commit bf8c4a9
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions quantum_module/quantum_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,53 @@
from qiskit.providers.aer import AerSimulator

# Define a function to generate a quantum key


def generate_quantum_key(size):
# Create a quantum circuit with two qubits
qc = QuantumCircuit(2)

# Apply Hadamard gates to both qubits
qc.h(0)
qc.h(1)

# Measure the qubits to generate a random key
qc.measure_all()

# Execute the circuit on a simulator
simulator = AerSimulator()
job = execute(qc, simulator, shots=1)
result = job.result()
key = result.get_counts(qc)

# Convert the key to a binary string
key_str = ''.join(format(x, 'b') for x in key)
key_str = "".join(format(x, "b") for x in key)

return key_str[:size]


# Define a function to encrypt data using quantum encryption


def encrypt_data(plain_text, key):
# Convert the plain text to a binary string
plain_text_bin = ''.join(format(ord(c), '08b') for c in plain_text)
plain_text_bin = "".join(format(ord(c), "08b") for c in plain_text)

# Encrypt the plain text using the quantum key
cipher_text_bin = ''.join(str(int(plain_text_bin[i]) ^ int(key[i % len(key)])) for i in range(len(plain_text_bin)))

cipher_text_bin = "".join(
str(int(plain_text_bin[i]) ^ int(key[i % len(key)]))
for i in range(len(plain_text_bin))
)

# Convert the cipher text back to a string
cipher_text = ''.join(chr(int(cipher_text_bin[i*8:i*8+8], 2)) for i in range(len(cipher_text_bin)//8))

cipher_text = "".join(
chr(int(cipher_text_bin[i * 8 : i * 8 + 8], 2))
for i in range(len(cipher_text_bin) // 8)
)

return cipher_text


# Example usage
key = generate_quantum_key(256)
plain_text = "This is a secret message"
Expand Down

0 comments on commit bf8c4a9

Please sign in to comment.