Skip to content

ewdlop/EncryptionProgramming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EncryptionProgramming

I ran the notebook on Google Colab. It works better on it.

Running this code on Linux probably works better too.

Image generates by the DALL·E on ChatGPT

https://colab.research.google.com/

b'' represents bye string in python

Private Key:b'-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAratBhWAUto1FbVixv0Qwh2yeQMW/GQ375FULqcdMW4Uput/U\nwIqwKwW/lOvS+icykiN20+xONysCtI7w0Lc0XZ0JuJGu1GzYJ9EtL3R9SQ2EShQI\n4HRBdmm80bO++rJ6P1hbh7MXmFPb2IggF8Lg3oNyhrd8lVrNlwvelFICaic4fPlq\nP2sgcelZ7gvyFXbNqgtle7YPssz7O43yfjEdnOBcInm/fQA3EjDS/OLzauJXVKQI\nydV282h3FddZc8covQ7qr0uCJx53bAgr+i80jQ6VFshls3tJdYnkyOxlLbBypaBB\nh4pUKsSh2I6r1LF/Kdz3x577FTxxfaZYFJ363wIDAQABAoIBABCqsk+MAIDifuq3\nC9voveWJQYjC0YukgWuQ09030LapyW7zQzY1OSHv28p9dVJnh51pxOIiuADoYkqU\nuzy0kFR5mTC63nXpejccBoOa4NktcGgxkwaDcbLdA+92GhpyHXRN1P7pa5bFWYBm\n0/mjzLPeFpQiMNUekUNxMqu2USABueyKKf7N81NEINVxUqbVlgIUXV8nP9Nozq/6\nsVaY9QJMOgoDN4C1Xnc84sRI51pP1E7GrygOcS6TBO7DiUWZu0bmHtOHJQdYKN3G\nOA/2hwkuuQBKanSaB4UV8oYJyKyljac3yNB1jZHEVDERoRQpVTkyZNWwD/EGKd9Q\nUcLOIWECgYEAv6A5MqiaJIkr8dVsrCqUWwYCRDWXaOKF+B1QBV9irlfwz0xY6zNF\nGjULCD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bh7MXmFPb2IggF8Lg\n3oNyhrd8lVrNlwvelFICaic4fPlqP2sgcelZ7gvyFXbNqgtle7YPssz7O43yfjEd\nnOBcInm/fQA3EjDS/OLzauJXVKQIydV282h3FddZc8covQ7qr0uCJx53bAgr+i80\njQ6VFshls3tJdYnkyOxlLbBypaBBh4pUKsSh2I6r1LF/Kdz3x577FTxxfaZYFJ36\n3wIDAQAB\n-----END PUBLIC KEY-----'

Message should be 'Secret Message' Candy

Password Generator RFC

RFC 972:Password Generator Protocol:该协议定义了一个基于TCP的密码生成服务,旨在为用户提供随机生成的密码。它强调了使用高随机性种子的重要性,并建议避免使用基于时间的种子。 RFC EDITOR

RFC 4086:Randomness Requirements for Security:该文档提供了安全应用中随机数生成的指导原则,强调了高质量随机数在密码学中的关键作用。

RFC 2898:PKCS #5: Password-Based Cryptography Specification Version 2.0:该标准描述了基于密码的加密方法,包括密钥派生函数PBKDF2,该函数常用于安全密码哈希。

RFC 6238:Time-Based One-Time Password Algorithm (TOTP):该RFC定义了基于时间的一次性密码算法,广泛用于双因素认证中。

...,

RFC ****: placeholder

Alice and Bob in Cryptographic Systems

In cryptographic systems, Alice and Bob are commonly used as placeholder names to explain how cryptographic protocols work. Alice wants to send a secure message to Bob, and they use various cryptographic techniques to ensure the message's confidentiality, integrity, and authenticity.

Example: Secure Communication between Alice and Bob

Step 1: Key Generation

Alice and Bob each generate a pair of public and private keys. The public key is shared with everyone, while the private key is kept secret.

Step 2: Encryption

Alice wants to send a secret message to Bob. She uses Bob's public key to encrypt the message. Only Bob's private key can decrypt this message.

from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding

# Load Bob's public key
with open("public_key.pem", "rb") as key_file:
    public_key = serialization.load_pem_public_key(key_file.read())

# Alice's secret message
message = b"Hello, Bob!"

# Encrypt the message using Bob's public key
encrypted_message = public_key.encrypt(
    message,
    padding.OAEP(
        mgf=padding.MGF1(algorithm=hashes.SHA256()),
        algorithm=hashes.SHA256(),
        label=None
    )
)

print("Encrypted message:", encrypted_message)

Step 3: Decryption

Bob receives the encrypted message and uses his private key to decrypt it.

from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding

# Load Bob's private key
with open("private_key.pem", "rb") as key_file:
    private_key = serialization.load_pem_private_key(key_file.read(), password=None)

# Decrypt the message using Bob's private key
decrypted_message = private_key.decrypt(
    encrypted_message,
    padding.OAEP(
        mgf=padding.MGF1(algorithm=hashes.SHA256()),
        algorithm=hashes.SHA256(),
        label=None
    )
)

print("Decrypted message:", decrypted_message.decode())

In this example, Alice and Bob use RSA encryption to securely communicate. Alice encrypts the message with Bob's public key, and Bob decrypts it with his private key. This ensures that only Bob can read the message, even if it is intercepted by someone else.

Why did the scarecrow become a successful cryptographer?

Because he was outstanding in his field!

Funny Image

Spanish Encryption

This section describes how to use the Spanish encryption Jupyter notebook.

Instructions

  1. Open the SpanishEncryption.ipynb notebook in Jupyter or Google Colab.
  2. Follow the instructions in the notebook to run the cells.
  3. The notebook includes functions for encryption and decryption of Spanish text using a simple substitution cipher.
  4. Examples and test cases are provided to demonstrate the usage of the functions.