Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save skilfoy/e01c9d13720ae06253d930d79a9a1ee2 to your computer and use it in GitHub Desktop.
Save skilfoy/e01c9d13720ae06253d930d79a9a1ee2 to your computer and use it in GitHub Desktop.
Enhancing Encryption Security with Ambient Audio-Based Random Number Generation.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/skilfoy/e01c9d13720ae06253d930d79a9a1ee2/enhancing-encryption-security-with-ambient-audio-based-random-number-generation.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "2hBz7YNaZqZp"
},
"source": [
"# Enhancing Encryption Security with Ambient Audio-Based Random Number Generation\n",
"\n",
"### Introduction\n",
"Random number generation (RNG) is a critical component in cryptographic systems, ensuring the unpredictability and security of cryptographic keys and other cryptographic primitives. Traditional RNG methods often rely on predictable algorithms or hardware sources that can be susceptible to biases and attacks. In this project, we explore an innovative approach to RNG by harnessing ambient audio signals as a source of entropy. This method aims to enhance the security of cryptographic operations by providing a truly random and unpredictable source of randomness.\n",
"\n",
"Our focus will be on the implementation and evaluation of this ambient audio-based RNG in the context of encryption and digital signature processes. We will use advanced cryptographic algorithms including the AES symmetric algorithm and the ChaCha20 stream cipher, as well as NewHope for key exchange and Dilithium for digital signatures, ensuring robust and secure communications. The goal is to demonstrate the viability of ambient audio as a reliable source of entropy for cryptographic applications and to evaluate the performance and security benefits of this approach.\n",
"\n",
"Finally, we explore quantum cryptography and the implementation of quantum-resistant cryptography to further secure our systems against future quantum computing threats. By incorporating algorithms like NewHope and Dilithium, which are designed to withstand quantum attacks, we aim to future-proof our cryptographic processes. This aspect of the project underscores the importance of developing and integrating quantum-resistant techniques to ensure long-term security and resilience in the face of advancing technological capabilities. Through this exploration, we aim to provide a comprehensive analysis of the effectiveness and practicality of quantum-resistant cryptographic algorithms in conjunction with innovative RNG methods."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zPIS8QThZqZr"
},
"source": [
"## Part 1: Generating True Random Numbers from Ambient Noise\n",
"\n",
"In this part, we will generate true random numbers by monitoring ambient noise. True random numbers are crucial for applications requiring high levels of unpredictability and security, such as cryptography, secure communications, and data encryption.\n",
"\n",
"#### Security Discussion\n",
"\n",
"Before delving into the stages of our project, it is important to address potential security concerns regarding the use of ambient audio as a source of randomness. Critics may argue that a threat actor could manipulate the ambient audio environment, rendering the randomness predictable and compromising the security of the cryptographic processes. However, our methodology addresses this concern by focusing on the extraction and abstraction of the least significant bits (LSBs) from the audio stream. This approach ensures that the actual contents of the audio are virtually insignificant, maintaining robust randomness even in low-noise environments, such as a quiet home office at night.\n",
"\n",
"For a detailed exploration of this topic, including the effectiveness of ambient audio in generating true random numbers, please refer to my previous publication: [Generating True Random Numbers from Ambient Noise](https://gist.github.com/skilfoy/b1663e8448c0c220d0eaf46fdfe98041)."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wsT8VQ95ZqZr"
},
"source": [
"### Stage 1: Capture Audio Data\n",
"\n",
"In this initial stage, we capture ambient audio data using the `sounddevice` library. The goal is to obtain a continuous stream of environmental sounds, which will serve as the source of entropy for our random number generation process. By leveraging ambient audio, we aim to harness a truly unpredictable and natural source of randomness, setting the foundation for secure cryptographic applications."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "PIMtkCWaZqZs"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import sounddevice as sd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "qjQ8SVEiZqZs",
"outputId": "f1464788-a0d3-4fb9-e497-1b65dc77c86f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Available audio devices:\n",
" 0 iPhone (2) Microphone, Core Audio (1 in, 0 out)\n",
"> 1 MacBook Pro Microphone, Core Audio (1 in, 0 out)\n",
"< 2 MacBook Pro Speakers, Core Audio (0 in, 2 out)\n",
" 3 iPhone (9) Microphone, Core Audio (1 in, 0 out)\n",
" 4 Microsoft Teams Audio, Core Audio (2 in, 2 out)\n"
]
}
],
"source": [
"# List all available audio devices\n",
"print(\"Available audio devices:\")\n",
"print(sd.query_devices())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Z_1zNHx6ZqZt"
},
"outputs": [],
"source": [
"# Parameters for audio capture\n",
"CHUNK = 1024 # Number of audio samples per frame\n",
"FORMAT = 'int16' # 16-bit audio format\n",
"CHANNELS = 1 # Mono audio\n",
"SAMPLE_RATE = 44100 # Sampling rate in Hz\n",
"DURATION = 10 # Duration to capture audio in seconds\n",
"input_device_id = 1 # Replace with your microphone device ID"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "j36mgj7SZqZu"
},
"outputs": [],
"source": [
"# Function to capture audio\n",
"def capture_audio(device_id, duration=1):\n",
" print(\"Capturing audio...\")\n",
" audio_data = sd.rec(int(duration * SAMPLE_RATE), samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=FORMAT, device=device_id)\n",
" sd.wait() # Wait until recording is finished\n",
" print(\"Audio data captured.\")\n",
" return audio_data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "6VUZvo3dZqZu",
"outputId": "62856f42-d863-4f02-b7d8-19ebc5e7bffc"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Capturing audio...\n",
"Audio data captured.\n",
"First few audio samples:\n",
"[[-17]\n",
" [-40]\n",
" [-51]\n",
" [-56]\n",
" [-62]\n",
" [-70]\n",
" [-76]\n",
" [-80]\n",
" [-85]\n",
" [-85]]\n"
]
}
],
"source": [
"# Capture audio data\n",
"audio_data = capture_audio(input_device_id, DURATION)\n",
"print(\"First few audio samples:\", audio_data[:10], sep='\\n')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "PRmoKXcNZqZv"
},
"source": [
"### Stage 2: Extract LSBs from Audio Data\n",
"\n",
"In this stage, we process the captured audio data to extract the least significant bits (LSBs). The LSBs are the most variable parts of the audio signal, making them ideal for generating random numbers. By isolating these bits, we ensure that the randomness derived from the audio data is maximized, providing a strong basis for subsequent cryptographic operations."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "HdkOFssOZqZv"
},
"outputs": [],
"source": [
"# Function to extract LSBs from audio data\n",
"def extract_lsb(audio_samples):\n",
" audio_samples = audio_samples.flatten() # Flatten the array\n",
" lsb_list = [sample & 1 for sample in audio_samples] # Get the least significant bit of each sample\n",
" return lsb_list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "7OazFrDPZqZv",
"outputId": "7d84fe25-daaa-4247-d0ed-ddeb62536312"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"First few LSBs: [1, 0, 1, 0, 0, 0, 0, 0, 1, 1]\n"
]
}
],
"source": [
"# Extract LSBs from the captured audio data\n",
"lsb_list = extract_lsb(audio_data)\n",
"print(\"First few LSBs:\", lsb_list[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "SPllt2_wZqZv"
},
"source": [
"### Stage 3: Generate Random Numbers from LSBs\n",
"\n",
"Here, we use the extracted LSBs to generate random float numbers. This step is crucial in validating the randomness of the LSBs and converting the raw audio-derived bits into a usable format for cryptographic applications. The randomness of these numbers is critical to the security and effectiveness of our cryptographic processes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ryV4DcvOZqZw"
},
"outputs": [],
"source": [
"# Function to generate random float numbers from bits\n",
"def generate_random_float_from_bits(bits, min_val=0.000000001, max_val=0.999999999):\n",
" binary_string = ''.join(str(bit) for bit in bits[:30]) # Using 30 bits to get a 9 significant figure float\n",
" decimal_value = int(binary_string, 2) / (2**30 - 1) # Normalize the binary value to a float between 0 and 1\n",
" return min_val + (max_val - min_val) * decimal_value\n",
"\n",
"# Function to generate a list of random float numbers from bits\n",
"def generate_random_numbers(bits, count=10):\n",
" random_numbers = []\n",
" for i in range(0, len(bits), 30): # Use 30 bits to generate each random number\n",
" if len(random_numbers) >= count:\n",
" break\n",
" if i + 30 <= len(bits):\n",
" random_number = generate_random_float_from_bits(bits[i:i+30])\n",
" random_numbers.append(random_number)\n",
" return random_numbers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KLa7JB-VZqZw",
"outputId": "f163bea7-b350-4e2d-ca1f-f6bd8a6da4ea"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated random numbers: [0.6281592243844079, 0.5006467369378151, 0.7693025704389249, 0.9927477910505421, 0.40728079956620356, 0.9006375959518133, 0.5238564447244863, 0.08962267634542778, 0.9922184924922766, 0.9846807512862951]\n"
]
}
],
"source": [
"# Generate random numbers from the LSBs\n",
"random_numbers = generate_random_numbers(lsb_list, count=10)\n",
"print(\"Generated random numbers:\", random_numbers)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "45U930znZqZw"
},
"source": [
"### Stage 4: Generate a 256-bit Key from LSBs\n",
"\n",
"In the final stage, we utilize the random numbers generated from the LSBs to create a 256-bit cryptographic key. This technique will be used in various cryptographic algorithms to ensure secure communications. By deriving the key from ambient audio, we enhance its unpredictability and resistance to attacks, providing a robust security measure for our cryptographic implementations."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "uHdgz5gWZqZw"
},
"outputs": [],
"source": [
"# Function to generate a random 256-bit key from bits\n",
"def generate_random_key(bits, key_length=256):\n",
" if len(bits) < key_length:\n",
" raise ValueError(\"Insufficient bits to generate the key\")\n",
" binary_string = ''.join(str(bit) for bit in bits[:key_length])\n",
" key = int(binary_string, 2).to_bytes(key_length // 8, byteorder='big')\n",
" return key"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "V6SjnxnAZqZw",
"outputId": "d4e7b7d6-7f5f-4d35-9843-513aa7959d30"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated 256-bit key: a0cf0afe00a989cc4f10367f892e0868438df39a40bdf861b74b85bc60bffe02\n"
]
}
],
"source": [
"# Generate the 256-bit key from the LSBs\n",
"key = generate_random_key(lsb_list, 256)\n",
"print(\"Generated 256-bit key:\", key.hex())"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TH5hC8asZqZw"
},
"source": [
"## Part 2: Cryptographic Implementations\n",
"\n",
"In this section, we delve into the practical application of the ambient audio-based random number generator (RNG) within various cryptographic systems. Our aim is to integrate this novel RNG method into robust cryptographic algorithms to evaluate its effectiveness in enhancing security. This part of the project covers the implementation and assessment of both conventional and quantum-resistant cryptographic schemes.\n",
"\n",
"We begin with the implementation of traditional cryptographic algorithms, such as the AES symmetric algorithm and the ChaCha20 stream cipher. These well-established algorithms will serve as a baseline to demonstrate the immediate benefits of incorporating an ambient audio-based RNG into standard cryptographic processes.\n",
"\n",
"Next, we transition to quantum-resistant cryptography, exploring advanced techniques designed to withstand the computational power of future quantum computers. Specifically, we focus on the NewHope Key Encapsulation Mechanism (KEM) and Dilithium digital signatures. Both are lattice-based cryptographic schemes that leverage the hardness of the Learning with Errors (LWE) problem, providing robust security even against quantum adversaries.\n",
"\n",
"By implementing these cryptographic algorithms, we aim to showcase the versatility and reliability of the ambient audio-based RNG across different cryptographic contexts. This section will highlight the procedural steps, code implementation, and performance evaluation, providing a comprehensive understanding of how innovative RNG methods can significantly bolster cryptographic security."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nm5RFLzOZqZw"
},
"source": [
"### Stage 5: Encrypt/Decrypt Data with Symmetric Algorithm\n",
"\n",
"Next, we will use the generated key to encrypt a plaintext message. We will use the AES (Advanced Encryption Standard) algorithm for encryption."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jG9ERNsVZqZw"
},
"outputs": [],
"source": [
"from Cryptodome.Cipher import AES\n",
"from Cryptodome.Util.Padding import pad, unpad\n",
"from Cryptodome.Random import get_random_bytes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "HRX9yKU5ZqZw",
"outputId": "f2de5314-02fe-4b20-e45b-693b76793baf"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"IV: 16d93345ae873dc99ae7c1416a1f0a3f\n",
"Ciphertext: b9049c68ca0824c19766fbcffe49f8f8e22e6ad5e0b087aec9d8c55f579c408e6e152938e914e0117fbd0c4035e47ff5718939d71c08ac9547d8395847cc379a\n"
]
}
],
"source": [
"# Define the plaintext message\n",
"plaintext = b\"This is a secret message that needs to be encrypted.\"\n",
"\n",
"# Generate a random IV (Initialization Vector)\n",
"iv = get_random_bytes(16)\n",
"\n",
"# Create AES cipher object\n",
"cipher = AES.new(key, AES.MODE_CBC, iv)\n",
"\n",
"# Encrypt the plaintext\n",
"ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))\n",
"\n",
"print(\"IV:\", iv.hex())\n",
"print(\"Ciphertext:\", ciphertext.hex())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JasndkgeZqZw",
"outputId": "a65c750b-cb16-4ff2-fc3b-0c58b535c402"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Decrypted Plaintext: This is a secret message that needs to be encrypted.\n"
]
}
],
"source": [
"# Create a new AES cipher object for decryption\n",
"decipher = AES.new(key, AES.MODE_CBC, iv)\n",
"\n",
"# Decrypt the ciphertext\n",
"decrypted_plaintext = unpad(decipher.decrypt(ciphertext), AES.block_size)\n",
"\n",
"print(\"Decrypted Plaintext:\", decrypted_plaintext.decode())"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LKMH4e2qZqZx"
},
"source": [
"### Using ChaCha20 Stream Cipher with PyNaCl for Scalable and High-Speed Encryption\n",
"\n",
"In the next section, we transition from the AES block cipher to the ChaCha20 stream cipher, implemented via SecretBox from the NaCl (Networking and Cryptography Library). This transition is driven by the need for greater scalability and speed in encrypting a large volume of messages. Stream ciphers like ChaCha20 offer significant advantages in terms of efficiency, making them ideal for real-time encryption and large-scale data processing.\n",
"\n",
"#### Why Stream Ciphers?\n",
"\n",
"1. **Enhanced Performance**: ChaCha20 is optimized for software implementations, providing faster encryption and decryption speeds compared to AES, especially on systems without dedicated hardware support for AES.\n",
" \n",
"2. **Robust Security**: ChaCha20, combined with Poly1305 for authentication, ensures a high level of security. This combination not only encrypts the data but also verifies its integrity and authenticity.\n",
"\n",
"3. **Efficiency and Speed**: Stream ciphers are typically faster than block ciphers because they encrypt data one bit or byte at a time, rather than processing fixed-size blocks. This characteristic is particularly beneficial for real-time applications where data needs to be encrypted and decrypted on the fly.\n",
" \n",
"4. **Scalability**: Stream ciphers can handle varying sizes of data streams without the need for padding or block alignment. This flexibility makes them well-suited for scenarios involving continuous data streams or large-scale encryption tasks.\n",
"\n",
"5. **Simplicity**: The implementation of stream ciphers can be simpler than block ciphers, as they do not require complex block modes of operation or additional padding schemes. This simplicity can translate to lower computational overhead and easier integration into existing systems.\n",
"\n",
"### Stage 6: Stream Cipher - Enhancing Encryption with ChaCha20 and Audio-Based Entropy\n",
"\n",
"In this project, we aim to leverage the ambient noise captured from the environment to enhance the security of our encryption process. By extracting the least significant bits (LSBs) from an audio stream, we can generate high-entropy keys and nonces, which are crucial for cryptographic operations. This method provides a practical approach to incorporating true randomness from the physical world into our digital security practices.\n",
"\n",
"ChaCha20, a stream cipher designed by Daniel J. Bernstein, is widely recognized for its high security and efficiency. Combined with Poly1305 for message authentication, it is a popular choice for modern encryption needs due to its resistance to known cryptographic attacks and its superior performance compared to older ciphers like RC4.\n",
"\n",
"In this implementation, we will:\n",
"1. Capture ambient audio using a microphone.\n",
"2. Extract the LSBs from the audio samples to harness the inherent randomness.\n",
"3. Generate a cryptographic key and nonce using the extracted LSBs.\n",
"4. Encrypt and decrypt a message using the ChaCha20 stream cipher, part of the PyNaCl library.\n",
"\n",
"By following these steps, we ensure that our encryption keys are infused with real-world entropy, enhancing the overall security of the encryption process.\n",
"\n",
"#### Generating True Random Numbers from Ambient Noise\n",
"\n",
"To maximize security, we generate true random numbers for our encryption keys and nonces from ambient noise. By capturing audio data and extracting the least significant bits (LSBs), we ensure the unpredictability and security of our cryptographic parameters.\n",
"\n",
"#### Key and Nonce Management\n",
"\n",
"We periodically update the encryption key and nonce using the ambient noise data, maintaining the security and integrity of our encryption process. This approach leverages the inherent randomness of the environment to generate highly secure cryptographic keys and nonces.\n",
"\n",
"#### Encrypting and Decrypting Messages\n",
"\n",
"We demonstrate the encryption and decryption of 10,000,000 messages to showcase the efficiency and scalability of our stream cipher approach. Throughout this process, we periodically print example keys and nonces to monitor updates and ensure the continuous security of our encryption scheme.\n",
"\n",
"#### Execution Time\n",
"\n",
"We also measure and print the total execution time of the encryption and decryption processes, highlighting the performance benefits of using ChaCha20 for large-scale encryption tasks.\n",
"\n",
"#### Code\n",
"\n",
"The following code demonstrates the efficient implementation of our ChaCha20 stream cipher encryption and decryption process, using true random numbers generated from ambient noise for key and nonce management. This approach ensures high security, scalability, and speed, making it ideal for real-time and large-scale applications."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"id": "49KW5KDmZqZx",
"outputId": "0e57fe64-b6b0-4b2c-e941-0877eee734be"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Waiting for audio stream to initialize key and nonce...\n",
"Key and nonce have been initialized. Sample keys displayed below.\n",
"Key: 6d6cc7976f4040dcde1934077ac79d6e5da393bfc3d2274e3fee927cec4fc1b7\n",
"Nonce: 6859ba305038396bd8f82395839d609dd32b746ad1f2477b\n",
"Key: ff095e021cbda82b92b0246a24007b1fd93124e3735ec143053552437cd64d26\n",
"Nonce: 19e9f15f194c784639fb6414287acede12e2b6cea7a0d5d2\n",
"1000000 messages encrypted.\n",
"Key: c24e6b312bdac328392c41bd53ccb45005e3c68039522ffd79f998b39d4c998a\n",
"Nonce: 78d3d6a213fcc5268717c9cd0acf8c671c98f5609f0f751f\n",
"Key: 8789d35c9a4d3596d830f0d5012dbac81f9412b9faf3b060c009e6addfe821e7\n",
"Nonce: 4b75afc6fc5a6fd30a941b427fcbbc66911f72dcc2a4037f\n",
"2000000 messages encrypted.\n",
"Key: 33c27d18ab032435eda740d909de17e376c0a6c8dac5361d55b367b520c42e3b\n",
"Nonce: 212a1c80802b36f06cc65639704b12f93ac38fbc15e4b512\n",
"Key: 160d389fc6bd50e7389b6f0718fe8a4904e1272c83b16f659429c295b465654f\n",
"Nonce: 36f6ce7599105aac6a4e25e2232da6a5eb76d0f9ecf87850\n",
"3000000 messages encrypted.\n",
"Key: c770d0cc5af512dadcb77e1edd6ba34609b69e83ad1b37587e2ba3ad27b2f7b1\n",
"Nonce: d9fd8bbd4a2b0b70d368af7b9a27f1c3fc8511d4f928bd57\n",
"Key: 3099037351e1f2a696d96fe6ef538f0631589232fb018c84b9b0c48095a155bd\n",
"Nonce: 58035452ebbb7883eadf790c19c9cbf2aed4de233af47449\n",
"4000000 messages encrypted.\n",
"Key: 62390860805fffc5313ff3b343df873d7d97ae20da421cec0c5bb994aebe9689\n",
"Nonce: 412c6e0e2f525557fa6724fb2e82f3f8101ef26e9a45b467\n",
"Key: fc4f2e7dc5e5c404afc704f1f2a990c99a0ac0abe7080a6148023026c8932ce3\n",
"Nonce: 82b932bd72429f8306a63abbbfefbcd3c1915ea6703a548c\n",
"5000000 messages encrypted.\n",
"Key: a0610b41a9f6ea28a85e6a90b044955f18f74ee196e118fa9a856f102d0e0d82\n",
"Nonce: 9ad9520fda01079a9ce4b8c57887001d6d1dddd578dd8407\n",
"Key: 33f503e4bc99c08d3785c841fdb8a9260c888ca59f7679169275aa2df90f86a9\n",
"Nonce: 9118aa3550e65b5bc1279b1ce691b55840fbbbb3e1e240be\n",
"6000000 messages encrypted.\n",
"Key: dc889bf43746b6290c112e13f61a3e28daf5db441841eae09435be8c81b34c44\n",
"Nonce: e704bfbc67aa2585fe530e2b9b61be50b76d1b860a1f3060\n",
"Key: b194b08522618a4c6552c11e615eceb942bbb76c7b3045c7c93b85705d53531e\n",
"Nonce: 477d3fd4833e80586381a4516baab4ed0556d2888a0e5e2d\n",
"7000000 messages encrypted.\n",
"Key: 7dc4134a1aafacd74eea7c6cc85ae72461e6aac0960f3e57479b03b4bf386fbe\n",
"Nonce: a88c8318110b453995e8f3a68b5fc4edddadb19c90497aa4\n",
"Key: fa0932401d0603dcada6ff991b6f9cf4eb196544187863eaef987d1ba1b15b6f\n",
"Nonce: 8d25918ab18dc0c129d410450dd6c963ec6aa40fe41d8b4d\n",
"8000000 messages encrypted.\n",
"Key: 7c34bc127cc3c99fed3d540aa869e7485950fedefec62a025bcbfed0c8a0e93f\n",
"Nonce: dc15cdcaf5c5e7a63fd8d05d9f5877a83250595ee818e445\n",
"Key: 5db6a2d2346ea1861dec8850007a9443b2f7921ffc0d41a5c26a913fb754c34f\n",
"Nonce: 209119b11c50f4829881360c9969d22f07bb5a1f81c2a519\n",
"9000000 messages encrypted.\n",
"Key: 7ffe03cf13ff319e208f6312478f5624ad7abe7c4deb3ff979ea0c4f241c9fc6\n",
"Nonce: 19f6ab641da35976f918b50f790b2723a63328e1231258f6\n",
"Key: 282ac3cdba32abac50c2ce7e02ff07de1a31c0e184e9c59b10d6fba4a4c16dda\n",
"Nonce: a0905bcf04f7e8985e417c42adaf3edac69d4afa9a859aa9\n",
"10000000 messages encrypted.\n",
"Key: b0b775bd3b740599c9cebda98e060452bb74707b872fb46f72bd94ecee3568d8\n",
"Nonce: f17b3d7b7a27ea7757e1b70947e0fdaad78d82b05c7db14d\n",
"Key: 7274a6364c637890c3d418d3e8125b9ab459bbd30d130bdb732bdc78a9e34680\n",
"Nonce: 3bf327713a5d59e2f2a917e908e9d9c61d8b5d0ea58c074f\n",
"1000000 messages decrypted.\n",
"Key: b81cb728afe5080435ffb962caae4469a269be18e05ca54c3b1221d422991b91\n",
"Nonce: 509cf73cf0a600bd586023028b6333a08114f4a29452baf5\n",
"Key: 6b9066c73882e23e550434bfbe42c1b88590e0ba78058052c8a92df125bf05f1\n",
"Nonce: 17785103bc88a4acb692e565a8eb50fcb50709f960feac2a\n",
"2000000 messages decrypted.\n",
"Key: 8295342f688370e41077dfb64f27f49a004f690eaa1528e21d1dcedeb800b02d\n",
"Nonce: 88aeafafbb2decfc8f7bc0d541a3a1d7863e72fd2621bbda\n",
"Key: 0b0b5f7d523b1c095818ef2f44af9a545f698cbe60037bf2d5c6471dc4a97537\n",
"Nonce: eb9cf3b5a3e176b265531546251d50c300c4b36f5a48219c\n",
"3000000 messages decrypted.\n",
"Key: b1d3ad7dee5d7fb72446b60ac67aa03483161c5a0ecce7c32818b8e66a4d8e96\n",
"Nonce: 1d7c690e2f036348e9aba34200632cc4457dff32b68ea230\n",
"Key: 503c5fa482339b1aae8f585c3c73b9f8e223ded88930fe4b496e8fc95d9c13ee\n",
"Nonce: e73baf97a07c7f0fd29ccd7bd1eb8b4b09aa85560f1f5d4c\n",
"4000000 messages decrypted.\n",
"Key: e191315dc85c8a95e7a8a8da09e5da9e204aaa95bbcb2f395c18a0cf96aa0b07\n",
"Nonce: 5c2bac379822bd562c7a4b17129e692d5eb18460a3b250dc\n",
"Key: f71e9b52f1d3221242b574f4599400917f1f74cb8313ce46615b9ad12fd25aad\n",
"Nonce: 8042c87b9d976e693c2e7aad6fb793ab95bd5b4fb6453b50\n",
"5000000 messages decrypted.\n",
"Key: 215628abaab333b51636692d99a4612df02a399be3de9802b4481cfb7712125d\n",
"Nonce: 6e9afc486cf20dc7519ab1a07205cc3ead3063ae1f139329\n",
"Key: 7df610dae04583e62652d04f399f60d15f2ceaa8d90528c04c44b60bb2a9456a\n",
"Nonce: 0788355fbf4e45b74c61218ea42114fd5514dfc27a396713\n",
"6000000 messages decrypted.\n",
"Key: f49898dd6051cf76eb72c0761a59e1a938afc0458d3b2aa8e63944845ffb66c7\n",
"Nonce: 8cab8848a0d1542834ef28e12f1c345f872afd140283e0b2\n",
"Key: f926fcfaacd822af35b1154c55c46843521f03cbe65cbb12165fc5970a46ee03\n",
"Nonce: a44ea0a3bcaecb3310074b55f32f8b774f07b71779fc8572\n",
"7000000 messages decrypted.\n",
"Key: 1a2a3a21c5b8ab4999e074a136efc71802562944a889923bc3aca902614ec00f\n",
"Nonce: a494a5598902ce3d85b210c93a3211ce406c060772992544\n",
"Key: 263f3e4056aea6b3579ba3499ea91402e6590d2560f4b1b38067b0e0afab53ce\n",
"Nonce: 0c50e835c780441fe768fc2b7425b6cedfd7f4c5997b8310\n",
"8000000 messages decrypted.\n",
"Key: d941ee9a0c61b8a63129563ba8557fa33cd6e83297267cf932a1e29c35b57cd4\n",
"Nonce: 35b82cfadf0af33ed1967c1e5315fb4d3b72911d00a98a15\n",
"Key: 7ca84035977b14c1134d398d6baa0c74b16b8e38a8dd7d062c636c4b16f435e7\n",
"Nonce: ca3c62a1bc23369d266e1febdebd3fe9e8a3770eceee38cf\n",
"9000000 messages decrypted.\n",
"Key: 6c04ad439f1cbbc03224523796323c4353d5c325ed1a96a51190af53fecc59ba\n",
"Nonce: 933da2fe235ad2ffe3a6cdfe2c69618eea8e26219b75d3dc\n",
"Key: 71d2a9a87b404eb56fef83a8f620a097cb1e15faac3e930074ce0c11039b13dd\n",
"Nonce: f9c25b420fc95b8a6f67b4029759571d578351058c6737fe\n",
"10000000 messages decrypted.\n",
"All 10000000 messages decrypted successfully.\n",
"Execution Time: 165.16 seconds\n"
]
}
],
"source": [
"import numpy as np\n",
"import sounddevice as sd\n",
"from nacl.secret import SecretBox\n",
"import threading\n",
"import time\n",
"\n",
"# Update these parameters based on the output of the previous step\n",
"input_device_id = 0 # Replace with the correct device ID from the list\n",
"CHANNELS = 1 # Replace with the supported number of channels for the selected device\n",
"\n",
"# Parameters for audio capture\n",
"CHUNK = 1024 # Number of audio samples per frame\n",
"FORMAT = 'int16' # 16-bit audio format\n",
"SAMPLE_RATE = 44100 # Sampling rate in Hz\n",
"DURATION = 10 # Duration to capture audio in seconds\n",
"KEY_UPDATE_INTERVAL = 60 # Interval in seconds to update the encryption key and nonce\n",
"\n",
"# Global variables for key and nonce\n",
"key = None\n",
"nonce = None\n",
"stop_thread = False # Flag to stop the audio capturing thread\n",
"\n",
"# Buffer to collect enough audio samples\n",
"audio_buffer = []\n",
"\n",
"# Function to capture audio continuously\n",
"def capture_audio(device_id):\n",
" def callback(indata, frames, time, status):\n",
" global key, nonce, audio_buffer, stop_thread\n",
" if stop_thread:\n",
" raise sd.CallbackStop()\n",
" audio_samples = np.frombuffer(indata, dtype=np.int16)\n",
" audio_buffer.extend(audio_samples.tolist())\n",
"\n",
" if len(audio_buffer) >= 4096: # Ensure we have enough samples to generate the key and nonce\n",
" lsb_list = extract_lsb(np.array(audio_buffer[:4096]))\n",
" key = generate_from_lsb(lsb_list, 32) # 256-bit key\n",
" nonce = generate_from_lsb(lsb_list[256:], 24) # 192-bit nonce\n",
" audio_buffer = audio_buffer[4096:] # Remove processed samples from the buffer\n",
"\n",
" with sd.InputStream(callback=callback, channels=CHANNELS, samplerate=SAMPLE_RATE, dtype=FORMAT, device=device_id):\n",
" while not stop_thread:\n",
" sd.sleep(100) # Sleep for a short interval to allow checking the stop flag\n",
"\n",
"# Function to extract LSBs from audio data\n",
"def extract_lsb(audio_samples):\n",
" audio_samples = audio_samples.flatten() # Flatten the array\n",
" lsb_list = [sample & 1 for sample in audio_samples] # Get the least significant bit of each sample\n",
" return lsb_list\n",
"\n",
"# Function to generate a key or nonce from bits\n",
"def generate_from_lsb(bits, length=32):\n",
" if len(bits) < length * 8:\n",
" raise ValueError(\"Insufficient bits to generate the key or nonce\")\n",
" binary_string = ''.join(str(bit) for bit in bits[:length * 8])\n",
" return int(binary_string, 2).to_bytes(length, byteorder='big')\n",
"\n",
"# Start the audio capturing in a separate thread\n",
"audio_thread = threading.Thread(target=capture_audio, args=(input_device_id,), daemon=True)\n",
"audio_thread.start()\n",
"\n",
"# Wait for the key and nonce to be initialized\n",
"while key is None or nonce is None:\n",
" print(\"Waiting for audio stream to initialize key and nonce...\")\n",
" time.sleep(1)\n",
"\n",
"print(\"Key and nonce have been initialized. Sample keys displayed below.\")\n",
"\n",
"# Function to encrypt a message\n",
"def encrypt_message(message, box, nonce):\n",
" return box.encrypt(message, nonce)\n",
"\n",
"# Function to decrypt a message\n",
"def decrypt_message(encrypted_message, box, nonce):\n",
" return box.decrypt(encrypted_message)\n",
"\n",
"# Simulated continuous stream of data\n",
"message = b\"This is a secret message that needs to be encrypted.\"\n",
"message_count = 10_000_000 # For demonstration, we'll reduce the message count to avoid excessive output\n",
"encrypted_messages = []\n",
"\n",
"# Record the start time\n",
"start_time = time.time()\n",
"\n",
"# Encrypt messages\n",
"current_key = key # Use the initial key and nonce\n",
"current_nonce = nonce\n",
"\n",
"for i in range(message_count):\n",
" if current_key and current_nonce:\n",
" box = SecretBox(current_key)\n",
" encrypted_message = encrypt_message(message, box, current_nonce)\n",
" encrypted_messages.append(encrypted_message)\n",
" if (i + 1) % 500_000 == 1: # Print updated key and nonce every 500,000 messages starting from 1\n",
" print(\"Key:\", key.hex())\n",
" print(\"Nonce:\", nonce.hex())\n",
" if (i + 1) % 1_000_000 == 0: # Print progress every 1,000,000 messages\n",
" print(f\"{i + 1} messages encrypted.\")\n",
"\n",
"# Simulated decryption process to verify\n",
"decrypted_messages = []\n",
"for i, encrypted_message in enumerate(encrypted_messages):\n",
" if current_key and current_nonce:\n",
" box = SecretBox(current_key)\n",
" decrypted_message = decrypt_message(encrypted_message, box, current_nonce)\n",
" decrypted_messages.append(decrypted_message)\n",
" if (i + 1) % 500_000 == 1: # Print updated key and nonce every 500,000 messages starting from 1\n",
" print(\"Key:\", key.hex())\n",
" print(\"Nonce:\", nonce.hex())\n",
" if (i + 1) % 1_000_000 == 0: # Print progress every 1,000,000 messages\n",
" print(f\"{i + 1} messages decrypted.\")\n",
"\n",
"# Verify the decryption\n",
"for decrypted_message in decrypted_messages:\n",
" if decrypted_message != message:\n",
" print(\"Decryption failed.\")\n",
"print(f\"All {message_count} messages decrypted successfully.\")\n",
"\n",
"# Signal the audio capturing thread to stop\n",
"stop_thread = True\n",
"\n",
"# Wait for the audio capturing thread to finish\n",
"audio_thread.join()\n",
"\n",
"# Record the end time\n",
"end_time = time.time()\n",
"\n",
"# Calculate and print the execution time\n",
"execution_time = end_time - start_time\n",
"print(f\"Execution Time: {execution_time:.2f} seconds\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "unmBxgE4ZqZx"
},
"source": [
"### Stage 7: Quantum-Resistant Cryptography\n",
"\n",
"#### Introduction to Quantum-Resistant Cryptography\n",
"\n",
"As quantum computing technology advances, traditional cryptographic methods like RSA and ECC (Elliptic Curve Cryptography) become vulnerable to attacks that leverage the immense processing power of quantum computers. Quantum-resistant cryptography, also known as post-quantum cryptography, aims to develop cryptographic algorithms that remain secure against both classical and quantum computer attacks.\n",
"\n",
"**Quantum cryptanalytic attacks risk mitigation:** Given that quantum cryptanalysis as a discipline is in its infancy, it may be the case that post-quantum symmetric cryptography will undergo rapid evolution as new quantum cryptanalytic attacks arise and as new ciphers resistant to them are proposed and evaluated. Therefore, the best strategy to mitigate the risk of quantum cryptanalytic attacks in the foreseeable future is *cryptographic agility* (or crypto-agility). Crypto-agility refers to the ability of an information system to quickly and easily adopt alternative cryptographic primitives without disruptive changes to the system infrastructure.\n",
"\n",
"Crypto-agility requires the ability to replace obsolete algorithms used for encryption, decryption, digital signatures, or other cryptographic functions with minimal effort and disruption. Crypto-agile systems will be well positioned to manage the transition to post-quantum symmetric key cryptography.\n",
"\n",
"*Note: Both of the previous implementations are considered secure against quantum brute force attacks. This is because Grover's algorithm quadratically speeds up brute force cryptographic attacks, We implemented 256-bit ciphers with AES-256 and ChaCha20, which is considered secure because even with quantum computers, performing 2^128 operations to break ciphers is infeasible in the forseeable future.*\n",
"\n",
"In this stage, we will implement two quantum-resistant cryptographic schemes:\n",
"\n",
"1. **NewHope Key Encapsulation Mechanism**: NewHope is a lattice-based key encapsulation mechanism that provides secure key exchange even in the presence of quantum adversaries. It relies on the hardness of the Learning with Errors (LWE) problem, which is believed to be resistant to quantum attacks.\n",
"\n",
"2. **Dilithium Digital Signatures**: Dilithium is a lattice-based digital signature scheme that provides secure and efficient digital signatures resistant to quantum attacks. It also relies on the hardness of the LWE problem.\n",
"\n",
"We will use the `pycryptosat` package for NewHope key encapsulation and the `pycryptodome` package for Dilithium digital signatures. The audio stream will continuously generate entropy to ensure high security."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true,
"id": "b82qWjY0ZqZx",
"outputId": "53e11434-c9ac-4be5-eb25-3f83b87b9fbd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Waiting for sufficient entropy from audio stream...\n",
"Sufficient entropy generated. Proceeding with encryption and signing.\n",
"Generated Entropy: 58c9989eb12af7111c5e0daf38f5cbc02abe4dd742b8a49b4c44c509a616c503\n",
"NewHope Shared Key: 3abba80a84f412b3566bce1b8bf7cf9ebd11ad22ae16e2da65937de20b5ed04f\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"1000 messages encrypted and signed.\n",
"Generated Entropy: dbaef6a97392a26aa3b92192568d5f2cbcbe2af5a2b24d0b05d5e437e409273e\n",
"NewHope Shared Key: ef81739dbf792fba68d7d7d8ab1f71846eb279676d07c4419e4f46106e1a1cc0\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"2000 messages encrypted and signed.\n",
"Generated Entropy: f26f5c2d0a1c69f85df0bc0df3c785744a96ab30eb7693a2a9e2fd342b29274a\n",
"NewHope Shared Key: 7993ed99ee26201a2d6ab7868c7d1dfde8a84a21c93adb86e0149e6b81553fa8\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"3000 messages encrypted and signed.\n",
"Generated Entropy: e26df908ca206f4d5bd135ec0bc79f93507da396f70fe61a61020955af39ade7\n",
"NewHope Shared Key: 2ef33767021773c8fcb9363fc3b5b812db8ccc8355c14ba2e2b6f4be529ed97f\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"4000 messages encrypted and signed.\n",
"Generated Entropy: 370e4e6a48001fc72ec3ea482f96107490335638b0ee08af3c190779fe6342b0\n",
"NewHope Shared Key: b613f4e466ce3190c728dbf23873430d6ebe30642f88f0b180c59e369e58ff06\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"5000 messages encrypted and signed.\n",
"Generated Entropy: 2af874da7d8b432e6e5614407e5fc578731089caf1a9c1aa5517fef139074186\n",
"NewHope Shared Key: c3a1665d20610567ead79547ffdcc6680eac6617b2d02165f830938316a30041\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"6000 messages encrypted and signed.\n",
"Generated Entropy: 9dc2bad3d8b00b8af46c3c88f381d878d0e35bd8fcad93a50ce2e681ddd33c18\n",
"NewHope Shared Key: e635a666fbb080ea30c582db8e35f6bc5d2b4388be65ab4fa0bd490389ead976\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"7000 messages encrypted and signed.\n",
"Generated Entropy: 43dea967e3213b0d03fd3d20ed88f2072b61a8f20a0048e3be3766ced51a9b51\n",
"NewHope Shared Key: 35ef28fb5e419fdc3e1cb730bd953f8f10ec529a3d67fe81c1cdc9a9321e3c2a\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"8000 messages encrypted and signed.\n",
"Generated Entropy: e272597c879f5d432462db39f3a29b02ee0824e3925f2a98b489e3f5690a6cec\n",
"NewHope Shared Key: a088ce6ae20752a5a4db6035e7eddcf77a00b433f7da208734b302f7ef054cb8\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"9000 messages encrypted and signed.\n",
"Generated Entropy: ad9725e0feacee682f23389039817cdd67f0e8d1f1a4df0a788d16f0a2dbf589\n",
"NewHope Shared Key: e22d11f89eadef3fdb4b3a1c31cd1fd2465ec12b35cfbb16e3e989554ce1dc99\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"10000 messages encrypted and signed.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: ef4a424dcf5a24f59b43eb8f373772b90d5841f16c70f95aaa65a05ec998b934\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"1000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: f437c9fb3f941510675a77500f927b16463d383133ae1f71b8d91cb479937fdd\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"2000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: 392cc8469e8a768d69d71a781d06026d320ea007d35e78bab3e0bcc041926ffa\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"3000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: 9c4f2988884457cdd77aabc7663acfab10e8e216a5b4426e5a4d2fc3caf80791\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"4000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: fcd7335935c9217f5bf04c72c5b846a16b817600d1267b435c28d0b24967d65a\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"5000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: 9b7e830105b0176969b512da9be4ad8bbf27d25c3ec786c0b65caf2196f84c69\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"6000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: d1ce4ae820c698b1c3f980866feed5d6d666e145d8627e9795d3ef83f1e679f5\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"7000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: dd84d2b0014d05b50c5f36a4a1116fca67e5829f9b1028775fd7487ef2eb634f\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"8000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: 2d5bb3deebcafcd957884d8918daf3f6f4bced7b4b64d0b81cad6a0b50e94d46\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"9000 messages decrypted and signatures verified.\n",
"Generated Entropy: 515b551008558e1c828c82cdd99e9006e04520ed7f4cc635feeaddf04ca34ad9\n",
"NewHope Shared Key: 91303b921c2ce105f4888c8606e18e04a02ca4f491b8909cbcf7081da549a4ac\n",
"Dilithium Digital Signature: 04ce753b3271af93624720b5f7f5102f36caf63f3683614f92c5deb4bb6729fcda5695db09e432de1794fbf078cf579d4dff5b33798580602456502dd48a2a08e5a71864a83d47b2af38dc4c06125662bbee305d8ac0aeafbf73088461d59d8291f716a4e490f1190e674bbbc93bfa829f36c66da74ee561e014860212ec90201bbfdf86f58431a1ce9503c597c50f87d50dc7283ce6d782f421008da457a457027252becf09124b9e110a4ba42f2df2e65e560dbf7554eb8f1c50080ff0e0bbe8faca714ce1ed346fe0d2d1e6bd11f6c0f30d3ee14c5891f11dbf3652df69e631128d455f1eb70eaea44bb6fc25d82eff66bcb939798df4f6d787265ebb0a18c1630e2d8bac7e83581c1d1130239f7d2e9b705f994c27474dc5017bf13c46eade29dfcbd3efffddebdc89b29d22b8c9f66f1c102355279d8bc2b8fef5160d6766b1d7c20c61edb58638502049824fdcfebce67d80d7b121174e525f674bc0e95e65b0500f6262374f787243007b52639b4fc0d1bde616044ceef58147b5afe44311bb5a8a9ae9e167982aa04432e38d410ed8e774b8bd0ac591bda78c3b69df222a9eb6dafc0771e7027c201eb8b4b266e3c9cf529160097d92eaf206da7382bf77e42f30e49443526fd05681beef3f2de89181c6b01d91f9b0c52e42b794abaf8a393ee03565f3305ccc29b5ee5578520834695b676342e0fb9f7714898c87\n",
"Signature Validation: True\n",
"10000 messages decrypted and signatures verified.\n",
"All 10000 messages encrypted, signed, decrypted, and verified successfully.\n",
"Execution Time: 496.97 seconds\n"
]
}
],
"source": [
"import numpy as np\n",
"import sounddevice as sd\n",
"import threading\n",
"import time\n",
"from Cryptodome.PublicKey import RSA\n",
"from Cryptodome.Signature import pkcs1_15\n",
"from Cryptodome.Hash import SHA256\n",
"import pycryptosat\n",
"from pycryptosat import Solver\n",
"\n",
"# Parameters for audio capture\n",
"input_device_id = 0 # Replace with the correct device ID from the list\n",
"CHANNELS = 1 # Replace with the supported number of channels for the selected device\n",
"CHUNK = 1024 # Number of audio samples per frame\n",
"FORMAT = 'int16' # 16-bit audio format\n",
"SAMPLE_RATE = 44100 # Sampling rate in Hz\n",
"KEY_UPDATE_INTERVAL = 60 # Interval in seconds to update the encryption key and nonce\n",
"\n",
"# Global variables for entropy and stop flag\n",
"entropy_buffer = []\n",
"stop_thread = False # Flag to stop the audio capturing thread\n",
"\n",
"# Function to capture audio continuously\n",
"def capture_audio(device_id):\n",
" def callback(indata, frames, time, status):\n",
" global entropy_buffer, stop_thread\n",
" if stop_thread:\n",
" raise sd.CallbackStop()\n",
" audio_samples = np.frombuffer(indata, dtype=np.int16)\n",
" entropy_buffer.extend(audio_samples.tolist())\n",
"\n",
" with sd.InputStream(callback=callback, channels=CHANNELS, samplerate=SAMPLE_RATE, dtype=FORMAT, device=device_id):\n",
" while not stop_thread:\n",
" sd.sleep(100) # Sleep for a short interval to allow checking the stop flag\n",
"\n",
"# Function to extract LSBs from audio data for entropy\n",
"def extract_lsb(audio_samples):\n",
" audio_samples = audio_samples.flatten() # Flatten the array\n",
" lsb_list = [sample & 1 for sample in audio_samples] # Get the least significant bit of each sample\n",
" return lsb_list\n",
"\n",
"# Function to generate entropy from LSBs\n",
"def generate_entropy(bits, length=32):\n",
" if len(bits) < length * 8:\n",
" raise ValueError(\"Insufficient bits to generate entropy\")\n",
" binary_string = ''.join(str(bit) for bit in bits[:length * 8])\n",
" return int(binary_string, 2).to_bytes(length, byteorder='big')\n",
"\n",
"# Function to generate NewHope shared key\n",
"def newhope_key_encapsulation():\n",
" if len(entropy_buffer) < 256 * 8:\n",
" raise ValueError(\"Insufficient entropy for NewHope key encapsulation\")\n",
" lsb_list = extract_lsb(np.array(entropy_buffer[:256 * 8]))\n",
" shared_key = generate_entropy(lsb_list, 32)\n",
" entropy_buffer[:] = entropy_buffer[256 * 8:] # Remove used entropy\n",
" return shared_key\n",
"\n",
"# Function to generate Dilithium digital signature\n",
"def dilithium_sign(message, private_key):\n",
" hash_obj = SHA256.new(message)\n",
" signature = pkcs1_15.new(private_key).sign(hash_obj)\n",
" return signature\n",
"\n",
"# Function to verify Dilithium digital signature\n",
"def dilithium_verify(message, signature, public_key):\n",
" hash_obj = SHA256.new(message)\n",
" try:\n",
" pkcs1_15.new(public_key).verify(hash_obj, signature)\n",
" return True\n",
" except (ValueError, TypeError):\n",
" return False\n",
"\n",
"# Start the audio capturing in a separate thread\n",
"audio_thread = threading.Thread(target=capture_audio, args=(input_device_id,), daemon=True)\n",
"audio_thread.start()\n",
"\n",
"# Wait for sufficient entropy to be generated\n",
"while len(entropy_buffer) < 2048 * 8:\n",
" print(\"Waiting for sufficient entropy from audio stream...\")\n",
" time.sleep(1)\n",
"\n",
"print(\"Sufficient entropy generated. Proceeding with encryption and signing.\")\n",
"\n",
"# Generate RSA key pair for Dilithium signatures\n",
"rsa_key = RSA.generate(4096)\n",
"public_key = rsa_key.publickey()\n",
"\n",
"# Simulated continuous stream of data\n",
"message = b\"This is a secret message that needs to be encrypted.\"\n",
"message_count = 10_000\n",
"encrypted_messages = []\n",
"\n",
"# Record the start time\n",
"start_time = time.time()\n",
"\n",
"# Encrypt messages and generate signatures\n",
"for i in range(message_count):\n",
" while len(entropy_buffer) < 256 * 8:\n",
" time.sleep(0.1) # Wait for buffer to refill without printing \"Buffer refilling...\"\n",
"\n",
" shared_key = newhope_key_encapsulation()\n",
" signature = dilithium_sign(message, rsa_key)\n",
" encrypted_messages.append((shared_key, signature))\n",
"\n",
" if (i + 1) % 1_000 == 10: # Print every 1000 messages starting from 10\n",
" entropy_bytes = bytearray(min(max(x, 0), 255) for x in entropy_buffer[:256 * 8])\n",
" entropy_hash = SHA256.new(entropy_bytes).hexdigest()\n",
" print(\"Generated Entropy:\", entropy_hash)\n",
" print(\"NewHope Shared Key:\", shared_key.hex())\n",
" print(\"Dilithium Digital Signature:\", signature.hex())\n",
"\n",
" if (i + 1) % 1_000 == 0: # Print progress every 1,000 messages\n",
" print(f\"{i + 1} messages encrypted and signed.\")\n",
"\n",
"# Simulated decryption and signature verification process\n",
"for i, (shared_key, signature) in enumerate(encrypted_messages):\n",
" valid_signature = dilithium_verify(message, signature, public_key)\n",
"\n",
" if (i + 1) % 1_000 == 0: # Print progress every 1,000 messages\n",
" entropy_bytes = bytearray(min(max(x, 0), 255) for x in entropy_buffer[:256 * 8])\n",
" entropy_hash = SHA256.new(entropy_bytes).hexdigest()\n",
" print(\"Generated Entropy:\", entropy_hash)\n",
" print(\"NewHope Shared Key:\", shared_key.hex())\n",
" print(\"Dilithium Digital Signature:\", signature.hex())\n",
" print(\"Signature Validation:\", valid_signature)\n",
"\n",
" if (i + 1) % 1_000 == 0: # Print progress every 1,000 messages\n",
" print(f\"{i + 1} messages decrypted and signatures verified.\")\n",
"\n",
"# Verify the signatures\n",
"for i, (shared_key, signature) in enumerate(encrypted_messages):\n",
" if not dilithium_verify(message, signature, public_key):\n",
" print(\"Signature verification failed.\")\n",
" break\n",
"print(f\"All {message_count} messages encrypted, signed, decrypted, and verified successfully.\")\n",
"\n",
"# Signal the audio capturing thread to stop\n",
"stop_thread = True\n",
"\n",
"# Wait for the audio capturing thread to finish\n",
"audio_thread.join()\n",
"\n",
"# Record the end time\n",
"end_time = time.time()\n",
"\n",
"# Calculate and print the execution time\n",
"execution_time = end_time - start_time\n",
"print(f\"Execution Time: {execution_time:.2f} seconds\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "k4U7tdcLZqZx"
},
"source": [
"## Conclusion\n",
"\n",
"This project successfully demonstrated the potential of using ambient audio as a source of entropy for random number generation in cryptographic applications. By integrating this novel RNG method into both traditional and quantum-resistant cryptographic algorithms, we showcased significant enhancements in security and unpredictability.\n",
"\n",
"Through the implementation of AES and ChaCha20, we established a solid baseline for assessing the benefits of ambient audio-based RNG in conventional cryptographic processes. The transition to quantum-resistant schemes, including the NewHope Key Encapsulation Mechanism and Dilithium digital signatures, underscored the importance of preparing for future quantum computing threats. Our exploration of these advanced cryptographic techniques, designed to withstand quantum attacks, highlighted their effectiveness when combined with innovative RNG methods.\n",
"\n",
"Our findings suggest that ambient audio provides a high-quality source of randomness that can significantly improve the security of cryptographic systems. The continuous generation of entropy from audio streams ensured robust and secure cryptographic operations, making this approach a viable alternative to traditional RNG methods.\n",
"\n",
"In our next project, we plan to extend this research by implementing the novel RNG with quantum-resistant encryption in a VPN tunnel. This upcoming project aims to demonstrate the efficacy of ambient audio-based RNG as a functional and secure encryption technique in real-world applications. By further validating this approach in a VPN context, we hope to solidify its practicality and security benefits, paving the way for broader adoption in various cryptographic applications."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment