strangerRidingCaml

3. Symmetric Cryptography 본문

Modern cryptography

3. Symmetric Cryptography

woddlwoddl 2024. 5. 6. 16:18
728x90
Symmetric Cryptography

Symmetric Cryptography

Symmetric Encryption Algorithms

  • DES (Data Encryption Standard): A block cipher with a 56-bit key size, widely used but now considered insecure due to its small key length.
  • AES (Advanced Encryption Standard): A block cipher with variable key lengths (128, 192, or 256 bits), currently considered secure and widely adopted.

Modes of Operation

  • ECB (Electronic Codebook): Encrypts each block of plaintext separately, making it vulnerable to patterns and identical blocks.
  • CBC (Cipher Block Chaining): XORs each plaintext block with the previous ciphertext block before encryption, adding randomness and preventing patterns.
  • CTR (Counter): Treats the key stream as a stream cipher, generating a unique nonce for each block to ensure both confidentiality and integrity.

Message Authentication Codes (MACs)

  • Used for data integrity verification and authentication.
  • Examples include HMAC (Hash-based Message Authentication Code) and CMAC (Cipher-based Message Authentication Code).

Key Management and Distribution

  • Crucial for securely sharing secret keys between parties.
  • Techniques include key exchange protocols (e.g., Diffie-Hellman) and key distribution centers.

Laboratory Activities

Lab 1: AES Encryption and Decryption in Python


from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes

def aes_encrypt(plaintext, key):
    cipher = AES.new(key, AES.MODE_ECB)
    ciphertext = cipher.encrypt(plaintext)
    return ciphertext

def aes_decrypt(ciphertext, key):
    cipher = AES.new(key, AES.MODE_ECB)
    plaintext = cipher.decrypt(ciphertext)
    return plaintext

key = get_random_bytes(16)
plaintext = b"Hello World"
ciphertext = aes_encrypt(plaintext, key)
decrypted_text = aes_decrypt(ciphertext, key)

print("Plaintext:", plaintext)
print("Ciphertext:", ciphertext)
print("Decrypted text:", decrypted_text)

This lab demonstrates the encryption and decryption of text using the AES algorithm in Electronic Codebook (ECB) mode.

Lab 2: Message Authentication Code (MAC) Generation in Python


import hashlib
import hmac

def generate_mac(message, key):
    h = hmac.new(key, message, hashlib.sha256)
    return h.hexdigest()

message = b"Hello World"
key = b"secret_key"
mac = generate_mac(message, key)

print("Message:", message)
print("MAC:", mac)

This lab illustrates the generation of a Message Authentication Code (MAC) for a given message using HMAC-SHA256 in Python.

'Modern cryptography' 카테고리의 다른 글

6. Cryptographic Protocols  (0) 2024.05.06
5. Hash Functions and Digital Signatures  (0) 2024.05.06
4. Public-Key Cryptography  (0) 2024.05.06
2. Classical Cryptography  (0) 2024.05.06
1. Introduction to Cryptography  (0) 2024.05.06