Hello I posted here yesterday about generating random 16 digits using Qiskit, and a gentle guy helped me but how about a string? How can I generate random 256 bit key in hex format in a superposition state and measure it?

Anyway something like this but using Qiskit instead:

def generate_key():

 return binascii.hexlify(os.urandom(32)).decode('utf-8').upper()

Output: CEF3A7BE7F95F3C27F393C74C99A2C1F1F8C658D3CD973C5FF3C266C7133AA38


1 Answer 1


A binary string can be converted into other formats such as decimal, octal and as you require, hexadecimal. As you have already mentioned, you need a 256-bit key. So you can replicate the same method as answered in here and set the number of qubits to be 256.

Repeat the same procedure and then convert the output to a hex format.

import coden
random_bits = get_random_bits(size=256) 
hex_key = coden.bin_to_hex(random_bits)

Here, get_random_bits will be constructed by you using your knowledge from the answer of the previous question.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.