From e29800942ee467955f134683bb766b222fb116dd Mon Sep 17 00:00:00 2001 From: dkrizhanovskyi Date: Thu, 8 Aug 2024 21:17:30 +0200 Subject: [PATCH] New commit --- CODE_OF_CONDUCT.md | 79 ++++++++++++ CONTRIBUTING.md | 83 ++++++++++++ DETAILED_ALGORITHMS.md | 68 ++++++++++ INSTALLATION.md | 80 ++++++++++++ README.md | 35 ++++- ROADMAP.md | 67 ++++++++++ SUPPORT.md | 45 +++++++ USAGE.md | 120 ++++++++++++++++++ classical_cryptography/README.md | 17 +++ classical_cryptography/algorithms/README.md | 15 +++ .../algorithms/aes_example.py | 33 +++++ .../algorithms/ecc_example.py | 39 ++++++ .../algorithms/rsa_example.py | 25 ++++ .../algorithms/test_aes_example.py | 28 ++++ .../algorithms/test_ecc_example.py | 25 ++++ .../algorithms/test_rsa_example.py | 24 ++++ quantum_cryptography/README.md | 25 ++++ 17 files changed, 804 insertions(+), 4 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 DETAILED_ALGORITHMS.md create mode 100644 INSTALLATION.md create mode 100644 ROADMAP.md create mode 100644 SUPPORT.md create mode 100644 USAGE.md create mode 100644 classical_cryptography/README.md create mode 100644 classical_cryptography/algorithms/README.md create mode 100644 classical_cryptography/algorithms/aes_example.py create mode 100644 classical_cryptography/algorithms/ecc_example.py create mode 100644 classical_cryptography/algorithms/rsa_example.py create mode 100644 classical_cryptography/algorithms/test_aes_example.py create mode 100644 classical_cryptography/algorithms/test_ecc_example.py create mode 100644 classical_cryptography/algorithms/test_rsa_example.py create mode 100644 quantum_cryptography/README.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3dab778 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,79 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..60dcabf --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,83 @@ +# Contributing to Crypto Comparison Project + +Thank you for your interest in contributing to our project! We welcome contributions from the community and aim to make the process as smooth and transparent as possible. + +## How to Contribute + +### Reporting Issues + +If you find any bugs or have suggestions for improvements, please open an issue on GitHub. Provide as much detail as possible, including steps to reproduce the issue and any relevant information. + +### Submitting Pull Requests + +To contribute code, please follow these steps: + +1. **Fork the Repository** + + Fork the repository to your own GitHub account. + +2. **Clone the Forked Repository** + + ```sh + git clone https://github.com/dkrizhanovskyi/crypto-comparison.git + cd crypto-comparison + ``` + +3. **Create a New Branch** + + Create a new branch for your feature or bug fix. + + ```sh + git checkout -b feature-name + ``` + +4. **Make Your Changes** + + Make your changes in the new branch. Ensure your code follows the project's coding standards. + +5. **Commit Your Changes** + + Commit your changes with a clear and descriptive commit message. + + ```sh + git add . + git commit -m "Description of your changes" + ``` + +6. **Push to Your Fork** + + Push your changes to your forked repository. + + ```sh + git push origin feature-name + ``` + +7. **Submit a Pull Request** + + Open a pull request from your fork to the main repository. Provide a clear description of your changes and any relevant information. + +### Coding Standards + +Please adhere to the following coding standards: + +- **Python**: Follow PEP 8 guidelines. Use linters such as `flake8` to ensure code quality. +- **Documentation**: Ensure all functions and classes are well-documented. Use docstrings to describe the purpose and usage of your code. + +### Testing + +Ensure that your code is well-tested. Add unit tests for any new functionality and run all tests to ensure nothing is broken. + +```sh +python -m unittest discover +``` + +### Code of Conduct + +By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md). Please treat others with respect and kindness. + +## Getting Help + +If you have any questions or need help, feel free to open an issue or contact the project maintainers. + +Thank you for your contributions! + diff --git a/DETAILED_ALGORITHMS.md b/DETAILED_ALGORITHMS.md new file mode 100644 index 0000000..7c94fbf --- /dev/null +++ b/DETAILED_ALGORITHMS.md @@ -0,0 +1,68 @@ +# Detailed Descriptions of Cryptographic Algorithms + +This document provides detailed descriptions of various cryptographic algorithms used in classical and quantum cryptography. Each algorithm is explained with its principles, security aspects, and example implementations. + +## Classical Cryptographic Algorithms + +### RSA (Rivest-Shamir-Adleman) + +RSA is an asymmetric cryptographic algorithm based on the mathematical difficulty of factoring large integers. + +- **Principles**: Uses a pair of keys, public and private, for encryption and decryption. Security relies on the difficulty of factoring the product of two large prime numbers. +- **Security**: Secure with key sizes of 2048 bits or more. Vulnerable to quantum attacks. +- **Example Implementation**: See `classical_cryptography/algorithms/rsa_example.py`. + +### AES (Advanced Encryption Standard) + +AES is a symmetric encryption algorithm widely used for securing data. + +- **Principles**: Uses the same key for both encryption and decryption. Operates on fixed block sizes of 128 bits with key sizes of 128, 192, or 256 bits. +- **Security**: Considered secure when using sufficient key lengths (128 bits or more). Resistant to known cryptographic attacks. +- **Example Implementation**: See `classical_cryptography/algorithms/aes_example.py`. + +### ECC (Elliptic Curve Cryptography) + +ECC is an asymmetric cryptographic algorithm based on the algebraic structure of elliptic curves over finite fields. + +- **Principles**: Uses elliptic curves to generate public and private keys. Provides strong security with smaller key sizes compared to RSA. +- **Security**: Secure against classical attacks and provides strong security with smaller key sizes (e.g., 256-bit ECC key is comparable to a 3072-bit RSA key). Vulnerable to quantum attacks. +- **Example Implementation**: See `classical_cryptography/algorithms/ecc_example.py`. + +## Quantum Cryptographic Protocols + +### Quantum Key Distribution (QKD) + +QKD uses principles of quantum mechanics to securely distribute cryptographic keys. + +- **Principles**: Relies on quantum states and the Heisenberg Uncertainty Principle to detect eavesdropping. The most common protocol is BB84. +- **Security**: Provides unconditional security based on the laws of quantum mechanics. Immune to quantum attacks. +- **Example Implementation**: See `quantum_cryptography/protocols/qkd_example.py`. + +### BB84 Protocol + +BB84 is a QKD protocol that uses photon polarization states to encode and distribute keys. + +- **Principles**: Uses random bases for encoding and measuring photon states. Key sifting is performed to generate a secure shared key. +- **Security**: Provides security against eavesdropping based on quantum mechanics. +- **Example Implementation**: See `quantum_cryptography/protocols/bb84_example.py`. + +### Grover's Algorithm + +Grover's algorithm is a quantum algorithm that provides a quadratic speedup for unstructured search problems. + +- **Principles**: Uses quantum superposition and interference to search an unsorted database in \(O(\sqrt{N})\) time. +- **Security**: Demonstrates the power of quantum computing in solving specific problems faster than classical algorithms. +- **Example Implementation**: See `quantum_cryptography/protocols/grover_example.py`. + +### Quantum Teleportation + +Quantum teleportation is a protocol for transferring quantum states between distant locations using entanglement. + +- **Principles**: Uses entangled particles and classical communication to transfer quantum information. +- **Security**: Demonstrates fundamental quantum principles and can be used in quantum communication. +- **Example Implementation**: See `quantum_cryptography/protocols/quantum_teleportation_example.py`. + +## References + +- For more detailed information on cryptographic algorithms, see resources such as [SpringerLink](https://link.springer.com/), [arXiv](https://arxiv.org/), and [IEEE Xplore](https://ieeexplore.ieee.org/). +- Additional details on quantum cryptography can be found on [Quantum Cryptography Wikipedia](https://en.wikipedia.org/wiki/Quantum_cryptography). diff --git a/INSTALLATION.md b/INSTALLATION.md new file mode 100644 index 0000000..93e1667 --- /dev/null +++ b/INSTALLATION.md @@ -0,0 +1,80 @@ +# Installation Guide + +This document provides step-by-step instructions for setting up the environment and installing the dependencies required to run the examples and tests in the Crypto Comparison Project. + +## Prerequisites + +Ensure that you have the following software installed on your system: + +- Python 3.7 or higher +- Git + +## Cloning the Repository + +First, clone the repository to your local machine: + +```sh +git clone https://github.com/dkrizhanovskyi/crypto-comparison.git +cd crypto-comparison +``` + +## Setting Up a Virtual Environment + +It's recommended to create a virtual environment to manage dependencies. Run the following commands to create and activate a virtual environment: + +```sh +python -m venv venv +source venv/bin/activate # On Windows use `venv\Scripts\activate` +``` + +## Installing Dependencies + +Install the required Python packages using `pip`: + +```sh +pip install -r requirements.txt +``` + +The `requirements.txt` file should include the following packages: + +```txt +qiskit +pycryptodome +``` + +## Running Examples + +To run the example scripts, navigate to the corresponding directory and execute the script: + +```sh +python classical_cryptography/algorithms/rsa_example.py +python classical_cryptography/algorithms/aes_example.py +python classical_cryptography/algorithms/ecc_example.py +python quantum_cryptography/protocols/qkd_example.py +python quantum_cryptography/protocols/bb84_example.py +python quantum_cryptography/protocols/grover_example.py +python quantum_cryptography/protocols/quantum_teleportation_example.py +python quantum_cryptography/protocols/quantum_encryption_example.py +python quantum_cryptography/protocols/quantum_superposition_entanglement_example.py +``` + +## Running Tests + +To run the tests, use the following command: + +```sh +python -m unittest discover +``` + +This command will discover and run all test cases in the repository. + +## Additional Resources + +- [Qiskit Documentation](https://qiskit.org/documentation/) +- [PyCryptodome Documentation](https://www.pycryptodome.org/src/installation) + +If you encounter any issues during installation or setup, please open an issue on GitHub. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details. diff --git a/README.md b/README.md index 6d5bfd1..91dd34d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # Comparison of Classical and Quantum Cryptography This project aims to compare classical and quantum cryptography. We will examine the basic principles, algorithms, protocols, security, and applications of these technologies. @@ -5,7 +6,37 @@ This project aims to compare classical and quantum cryptography. We will examine ## Project Structure - `classical_cryptography/`: Materials on classical cryptography. + - `overview.md`: General overview of classical cryptography. + - `algorithms/`: Detailed descriptions and examples of classical cryptographic algorithms. + - `rsa.md`: Detailed description of RSA algorithm. + - `rsa_example.py`: Example code for RSA algorithm. + - `test_rsa_example.py`: Tests for RSA example code. + - `aes.md`: Detailed description of AES algorithm. + - `aes_example.py`: Example code for AES algorithm. + - `test_aes_example.py`: Tests for AES example code. + - `ecc.md`: Detailed description of ECC algorithm. + - `ecc_example.py`: Example code for ECC algorithm. + - `test_ecc_example.py`: Tests for ECC example code. - `quantum_cryptography/`: Materials on quantum cryptography. + - `overview.md`: General overview of quantum cryptography. + - `protocols/`: Detailed descriptions and examples of quantum cryptographic protocols. + - `qkd.md`: Detailed description of QKD protocol. + - `qkd_example.py`: Example code for QKD protocol. + - `test_qkd_example.py`: Tests for QKD example code. + - `bb84_example.py`: Example code for BB84 protocol. + - `test_bb84_example.py`: Tests for BB84 example code. + - `ecc_qkd_example.py`: Example code for ECC in QKD. + - `test_ecc_qkd_example.py`: Tests for ECC in QKD example code. + - `grover_example.py`: Example code for Grover's algorithm. + - `test_grover_example.py`: Tests for Grover's algorithm example code. + - `quantum_teleportation_example.py`: Example code for quantum teleportation. + - `test_quantum_teleportation_example.py`: Tests for quantum teleportation example code. + - `bb84_qiskit_example.py`: Example code for BB84 on Qiskit. + - `test_bb84_qiskit_example.py`: Tests for BB84 on Qiskit example code. + - `quantum_encryption_example.py`: Example code for quantum encryption. + - `test_quantum_encryption_example.py`: Tests for quantum encryption example code. + - `quantum_superposition_entanglement_example.py`: Example code for quantum superposition and entanglement. + - `test_quantum_superposition_entanglement_example.py`: Tests for quantum superposition and entanglement example code. - `comparison.md`: Comparison of classical and quantum cryptography. ## Goals @@ -23,10 +54,6 @@ git clone https://github.com/dkrizhanovskyi/crypto-comparison.git cd crypto-comparison ``` -## Contributing - -We welcome contributions! Please read our [contributing guidelines](CONTRIBUTING.md) before making any changes. - ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..565794f --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,67 @@ +# Project Roadmap + +This document outlines the planned features, improvements, and future directions for the Crypto Comparison Project. + +## Phase 1: Initial Release + +- [x] Set up project repository and structure +- [x] Implement classical cryptography algorithms + - [x] RSA: Key generation, encryption, decryption + - [x] AES: Symmetric encryption and decryption + - [x] ECC: Key generation, signing, verification +- [x] Implement quantum cryptography protocols + - [x] QKD: Quantum Key Distribution + - [x] BB84: BB84 protocol + - [x] Grover's Algorithm: Quantum search algorithm + - [x] Quantum Teleportation: Teleportation protocol + - [x] Quantum Encryption: Quantum encryption protocol + - [x] Quantum Superposition and Entanglement: Creation of superposition and entanglement states +- [x] Add comprehensive tests for all examples +- [x] Documentation + - [x] README.md + - [x] CONTRIBUTING.md + - [x] CODE_OF_CONDUCT.md + - [x] DETAILED_ALGORITHMS.md + - [x] INSTALLATION.md + - [x] USAGE.md + - [x] ROADMAP.md + +## Phase 2: Enhancements and New Features + +- [ ] Expand classical cryptography section + - [ ] Implement additional algorithms (e.g., DES, Blowfish) + - [ ] Add more detailed security analysis +- [ ] Expand quantum cryptography section + - [ ] Implement Shor's Algorithm + - [ ] Add more detailed explanations of quantum principles +- [ ] Performance optimization + - [ ] Optimize classical algorithms for speed and efficiency + - [ ] Optimize quantum circuits for fewer gates and lower depth +- [ ] Advanced examples + - [ ] Real-world use cases of quantum cryptography + - [ ] Hybrid approaches combining classical and quantum cryptography +- [ ] Interactive tutorials + - [ ] Develop Jupyter notebooks for interactive learning + - [ ] Include step-by-step guides and explanations + +## Phase 3: Community and Collaboration + +- [ ] Community engagement + - [ ] Encourage contributions and feedback from the community + - [ ] Host discussions and Q&A sessions +- [ ] Collaborations with academic and industry experts + - [ ] Partner with universities and research institutions + - [ ] Collaborate with industry professionals for real-world applications +- [ ] Workshops and webinars + - [ ] Organize online workshops to educate and engage users + - [ ] Conduct webinars on advanced topics in cryptography + +## Long-term Goals + +- [ ] Keep the project updated with the latest advancements in cryptography +- [ ] Establish the project as a comprehensive resource for learning and implementing cryptographic algorithms +- [ ] Foster a collaborative environment for continuous learning and innovation + +We welcome suggestions and contributions from the community to help shape the future of this project. Please open an issue or submit a pull request with your ideas and improvements. + +Thank you for your support and contribution! diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..fc9e491 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,45 @@ +# Support + +Thank you for using the Crypto Comparison Project. This document provides information on how to get support, report issues, and contribute to the project. + +## Getting Help + +If you need help with the project, you can: + +- **Read the Documentation**: Check the provided documentation files for detailed information on installation, usage, and contributing. +- **Search the Issues**: Look for existing issues on GitHub to see if your question has already been answered. + +## Reporting Issues + +If you encounter a bug or have a suggestion for improvement, please open an issue on GitHub: + +1. **Go to the Issues Page**: [GitHub Issues](https://github.com/dkrizhanovskyi/crypto-comparison/issues) +2. **Click on "New Issue"**: Provide a clear and detailed description of the problem or suggestion. +3. **Include Relevant Information**: Include any relevant details, such as steps to reproduce the issue, screenshots, and your system configuration. + +## Contributing + +We welcome contributions from the community! If you would like to contribute, please follow these steps: + +1. **Fork the Repository**: Fork the repository to your own GitHub account. +2. **Clone the Forked Repository**: Clone the repository to your local machine. +3. **Create a New Branch**: Create a new branch for your feature or bug fix. +4. **Make Your Changes**: Make your changes in the new branch. +5. **Commit Your Changes**: Commit your changes with a clear and descriptive commit message. +6. **Push to Your Fork**: Push your changes to your forked repository. +7. **Submit a Pull Request**: Open a pull request from your fork to the main repository. Provide a clear description of your changes and any relevant information. + +For more detailed guidelines, please refer to the [Contributing Guide](CONTRIBUTING.md). + +## Code of Conduct + +By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md). Please treat others with respect and kindness. + +## Contact + +If you have any questions or need further assistance, you can contact the project maintainers: + +- **Email**: [daniil.krizhanovskyi@hotmail.com](mailto:daniil.krizhanovskyi@hotmail.com) +- **GitHub**: [dkrizhanovskyi](https://github.com/dkrizhanovskyi) + +Thank you for your support and contributions! diff --git a/USAGE.md b/USAGE.md new file mode 100644 index 0000000..96944fb --- /dev/null +++ b/USAGE.md @@ -0,0 +1,120 @@ +# Usage Guide + +This document provides instructions on how to use the scripts and functionalities provided in the Crypto Comparison Project. + +## Running Classical Cryptography Examples + +### RSA Example + +The RSA example demonstrates key generation, encryption, and decryption using RSA. + +To run the RSA example: + +```sh +python classical_cryptography/algorithms/rsa_example.py +``` + +### AES Example + +The AES example demonstrates symmetric encryption and decryption using AES. + +To run the AES example: + +```sh +python classical_cryptography/algorithms/aes_example.py +``` + +### ECC Example + +The ECC example demonstrates key generation, signing, and verification using Elliptic Curve Cryptography. + +To run the ECC example: + +```sh +python classical_cryptography/algorithms/ecc_example.py +``` + +## Running Quantum Cryptography Examples + +### QKD Example + +The QKD example demonstrates the Quantum Key Distribution protocol. + +To run the QKD example: + +```sh +python quantum_cryptography/protocols/qkd_example.py +``` + +### BB84 Example + +The BB84 example demonstrates the BB84 protocol for Quantum Key Distribution. + +To run the BB84 example: + +```sh +python quantum_cryptography/protocols/bb84_example.py +``` + +### Grover's Algorithm Example + +The Grover's algorithm example demonstrates a quantum search algorithm. + +To run the Grover's algorithm example: + +```sh +python quantum_cryptography/protocols/grover_example.py +``` + +### Quantum Teleportation Example + +The quantum teleportation example demonstrates the quantum teleportation protocol. + +To run the quantum teleportation example: + +```sh +python quantum_cryptography/protocols/quantum_teleportation_example.py +``` + +### Quantum Encryption Example + +The quantum encryption example demonstrates a quantum encryption protocol. + +To run the quantum encryption example: + +```sh +python quantum_cryptography/protocols/quantum_encryption_example.py +``` + +### Quantum Superposition and Entanglement Example + +The quantum superposition and entanglement example demonstrates the creation of superposition and entanglement states. + +To run the quantum superposition and entanglement example: + +```sh +python quantum_cryptography/protocols/quantum_superposition_entanglement_example.py +``` + +## Running Tests + +To ensure that the implementations are working correctly, run the tests provided in the repository: + +```sh +python -m unittest discover +``` + +This command will discover and run all test cases. + +## Additional Resources + +For more detailed information on the cryptographic algorithms and protocols used in this project, refer to the following resources: + +- [Qiskit Documentation](https://qiskit.org/documentation/) +- [PyCryptodome Documentation](https://www.pycryptodome.org/src/installation) +- [Quantum Cryptography Wikipedia](https://en.wikipedia.org/wiki/Quantum_cryptography) +- [SpringerLink](https://link.springer.com/) +- [arXiv](https://arxiv.org/) +- [IEEE Xplore](https://ieeexplore.ieee.org/) + +If you have any questions or need further assistance, please open an issue on GitHub. diff --git a/classical_cryptography/README.md b/classical_cryptography/README.md new file mode 100644 index 0000000..9c086bd --- /dev/null +++ b/classical_cryptography/README.md @@ -0,0 +1,17 @@ +# Classical Cryptography + +This directory contains materials related to classical cryptography. It includes overviews, detailed descriptions, example implementations, and tests for various classical cryptographic algorithms. + +## Contents + +- `overview.md`: General overview of classical cryptography. +- `algorithms/`: Directory containing detailed descriptions and example implementations of classical cryptographic algorithms. + - `rsa.md`: Detailed description of the RSA algorithm. + - `rsa_example.py`: Example code for the RSA algorithm. + - `test_rsa_example.py`: Tests for RSA example code. + - `aes.md`: Detailed description of the AES algorithm. + - `aes_example.py`: Example code for the AES algorithm. + - `test_aes_example.py`: Tests for AES example code. + - `ecc.md`: Detailed description of the ECC algorithm. + - `ecc_example.py`: Example code for the ECC algorithm. + - `test_ecc_example.py`: Tests for ECC example code. diff --git a/classical_cryptography/algorithms/README.md b/classical_cryptography/algorithms/README.md new file mode 100644 index 0000000..2bba796 --- /dev/null +++ b/classical_cryptography/algorithms/README.md @@ -0,0 +1,15 @@ +# Classical Cryptographic Algorithms + +This directory contains detailed descriptions, example implementations, and tests for various classical cryptographic algorithms. + +## Contents + +- `rsa.md`: Detailed description of the RSA algorithm. +- `rsa_example.py`: Example code for the RSA algorithm. +- `test_rsa_example.py`: Tests for RSA example code. +- `aes.md`: Detailed description of the AES algorithm. +- `aes_example.py`: Example code for the AES algorithm. +- `test_aes_example.py`: Tests for AES example code. +- `ecc.md`: Detailed description of the ECC algorithm. +- `ecc_example.py`: Example code for the ECC algorithm. +- `test_ecc_example.py`: Tests for ECC example code. diff --git a/classical_cryptography/algorithms/aes_example.py b/classical_cryptography/algorithms/aes_example.py new file mode 100644 index 0000000..673bd1a --- /dev/null +++ b/classical_cryptography/algorithms/aes_example.py @@ -0,0 +1,33 @@ +from Crypto.Cipher import AES +from Crypto.Random import get_random_bytes + +# Key generation +key = get_random_bytes(16) # AES-128 + +# Encryption +def encrypt(message, key): + cipher = AES.new(key, AES.MODE_EAX) + nonce = cipher.nonce + ciphertext, tag = cipher.encrypt_and_digest(message) + return nonce, ciphertext, tag + +# Decryption +def decrypt(nonce, ciphertext, tag, key): + cipher = AES.new(key, AES.MODE_EAX, nonce=nonce) + plaintext = cipher.decrypt(ciphertext) + try: + cipher.verify(tag) + return plaintext + except ValueError: + return None + +# Example usage +message = b'This is a secret message' +nonce, ciphertext, tag = encrypt(message, key) +print(f'Ciphertext: {ciphertext}') + +plaintext = decrypt(nonce, ciphertext, tag, key) +if plaintext: + print(f'Plaintext: {plaintext.decode("utf-8")}') +else: + print('Decryption failed') diff --git a/classical_cryptography/algorithms/ecc_example.py b/classical_cryptography/algorithms/ecc_example.py new file mode 100644 index 0000000..7ff9de9 --- /dev/null +++ b/classical_cryptography/algorithms/ecc_example.py @@ -0,0 +1,39 @@ +from Crypto.PublicKey import ECC +from Crypto.Signature import DSS +from Crypto.Hash import SHA256 + +# Key generation +private_key = ECC.generate(curve='P-256') +public_key = private_key.public_key() + +# Save keys to files +with open('ecc_private.pem', 'wt') as f: + f.write(private_key.export_key(format='PEM')) + +with open('ecc_public.pem', 'wt') as f: + f.write(public_key.export_key(format='PEM')) + +# Sign a message +def sign_message(message, private_key): + h = SHA256.new(message) + signer = DSS.new(private_key, 'fips-186-3') + signature = signer.sign(h) + return signature + +# Verify a signature +def verify_signature(message, signature, public_key): + h = SHA256.new(message) + verifier = DSS.new(public_key, 'fips-186-3') + try: + verifier.verify(h, signature) + return True + except ValueError: + return False + +# Example usage +message = b'This is a message to be signed' +signature = sign_message(message, private_key) +print(f'Signature: {signature}') + +is_valid = verify_signature(message, signature, public_key) +print(f'Signature valid: {is_valid}') diff --git a/classical_cryptography/algorithms/rsa_example.py b/classical_cryptography/algorithms/rsa_example.py new file mode 100644 index 0000000..772ea98 --- /dev/null +++ b/classical_cryptography/algorithms/rsa_example.py @@ -0,0 +1,25 @@ +from Crypto.PublicKey import RSA +from Crypto.Cipher import PKCS1_OAEP +from Crypto.Random import get_random_bytes + +# Key generation +key = RSA.generate(2048) +private_key = key.export_key() +public_key = key.publickey().export_key() + +# Save keys to files +with open('private.pem', 'wb') as f: + f.write(private_key) + +with open('public.pem', 'wb') as f: + f.write(public_key) + +# Encryption +message = b'This is a secret message' +cipher_rsa = PKCS1_OAEP.new(key.publickey()) +ciphertext = cipher_rsa.encrypt(message) + +# Decryption +cipher_rsa = PKCS1_OAEP.new(key) +plaintext = cipher_rsa.decrypt(ciphertext) +print(plaintext.decode('utf-8')) diff --git a/classical_cryptography/algorithms/test_aes_example.py b/classical_cryptography/algorithms/test_aes_example.py new file mode 100644 index 0000000..448c11f --- /dev/null +++ b/classical_cryptography/algorithms/test_aes_example.py @@ -0,0 +1,28 @@ +import unittest +from Crypto.Cipher import AES +from Crypto.Random import get_random_bytes +from aes_example import encrypt, decrypt + +class TestAESExample(unittest.TestCase): + + def test_encryption_decryption(self): + key = get_random_bytes(16) # AES-128 + message = b'This is a test message' + + nonce, ciphertext, tag = encrypt(message, key) + plaintext = decrypt(nonce, ciphertext, tag, key) + + self.assertEqual(plaintext, message) + + def test_decryption_failure(self): + key = get_random_bytes(16) # AES-128 + wrong_key = get_random_bytes(16) + message = b'This is a test message' + + nonce, ciphertext, tag = encrypt(message, key) + plaintext = decrypt(nonce, ciphertext, tag, wrong_key) + + self.assertIsNone(plaintext) + +if __name__ == '__main__': + unittest.main() diff --git a/classical_cryptography/algorithms/test_ecc_example.py b/classical_cryptography/algorithms/test_ecc_example.py new file mode 100644 index 0000000..1ba094c --- /dev/null +++ b/classical_cryptography/algorithms/test_ecc_example.py @@ -0,0 +1,25 @@ +import unittest +from Crypto.PublicKey import ECC +from ecc_example import sign_message, verify_signature + +class TestECCExample(unittest.TestCase): + + def setUp(self): + self.private_key = ECC.generate(curve='P-256') + self.public_key = self.private_key.public_key() + + def test_signature_verification(self): + message = b'This is a test message' + signature = sign_message(message, self.private_key) + is_valid = verify_signature(message, signature, self.public_key) + self.assertTrue(is_valid) + + def test_signature_failure(self): + message = b'This is a test message' + wrong_message = b'This is a different message' + signature = sign_message(message, self.private_key) + is_valid = verify_signature(wrong_message, signature, self.public_key) + self.assertFalse(is_valid) + +if __name__ == '__main__': + unittest.main() diff --git a/classical_cryptography/algorithms/test_rsa_example.py b/classical_cryptography/algorithms/test_rsa_example.py new file mode 100644 index 0000000..001f07b --- /dev/null +++ b/classical_cryptography/algorithms/test_rsa_example.py @@ -0,0 +1,24 @@ +import unittest +from Crypto.PublicKey import RSA +from Crypto.Cipher import PKCS1_OAEP + +class TestRSAExample(unittest.TestCase): + + def test_encryption_decryption(self): + # Key generation + key = RSA.generate(2048) + public_key = key.publickey() + + # Encryption + message = b'This is a test message' + cipher_rsa = PKCS1_OAEP.new(public_key) + ciphertext = cipher_rsa.encrypt(message) + + # Decryption + cipher_rsa = PKCS1_OAEP.new(key) + plaintext = cipher_rsa.decrypt(ciphertext) + + self.assertEqual(plaintext, message) + +if __name__ == '__main__': + unittest.main() diff --git a/quantum_cryptography/README.md b/quantum_cryptography/README.md new file mode 100644 index 0000000..896bd9a --- /dev/null +++ b/quantum_cryptography/README.md @@ -0,0 +1,25 @@ +# Quantum Cryptography + +This directory contains materials related to quantum cryptography. It includes overviews, detailed descriptions, example implementations, and tests for various quantum cryptographic protocols. + +## Contents + +- `overview.md`: General overview of quantum cryptography. +- `protocols/`: Directory containing detailed descriptions and example implementations of quantum cryptographic protocols. + - `qkd.md`: Detailed description of the QKD protocol. + - `qkd_example.py`: Example code for the QKD protocol. + - `test_qkd_example.py`: Tests for QKD example code. + - `bb84_example.py`: Example code for the BB84 protocol. + - `test_bb84_example.py`: Tests for BB84 example code. + - `ecc_qkd_example.py`: Example code for ECC in QKD. + - `test_ecc_qkd_example.py`: Tests for ECC in QKD example code. + - `grover_example.py`: Example code for Grover's algorithm. + - `test_grover_example.py`: Tests for Grover's algorithm example code. + - `quantum_teleportation_example.py`: Example code for quantum teleportation. + - `test_quantum_teleportation_example.py`: Tests for quantum teleportation example code. + - `bb84_qiskit_example.py`: Example code for BB84 on Qiskit. + - `test_bb84_qiskit_example.py`: Tests for BB84 on Qiskit example code. + - `quantum_encryption_example.py`: Example code for quantum encryption. + - `test_quantum_encryption_example.py`: Tests for quantum encryption example code. + - `quantum_superposition_entanglement_example.py`: Example code for quantum superposition and entanglement. + - `test_quantum_superposition_entanglement_example.py`: Tests for quantum superposition and entanglement example code.