| Download the amazing global Makindo app: Android | Apple | |
|---|---|
| MEDICAL DISCLAIMER: Educational use only. Not for diagnosis or management. See below for full disclaimer. |
Related Subjects: |Python |C |Java |C++ |C sharp |VB |Natural Language processing |How does a CPU work |Computer Networking |Computer Security |Concurrent Programming |Compilers |Cryptography |Data Structures |Database Management |Object orientated programming
Cryptography is the practice and study of techniques for securing communication and data from adversaries. It ensures the confidentiality, integrity, authenticity, and non-repudiation of information. Cryptography is fundamental to modern computer security, underpinning many technologies such as secure communications, digital signatures, and data encryption.
from cryptography.fernet import Fernet
# Generate a key
key = Fernet.generate_key()
cipher = Fernet(key)
# Encrypt data
plaintext = b"Secret message"
ciphertext = cipher.encrypt(plaintext)
print(f"Ciphertext: {ciphertext}")
# Decrypt data
decrypted_text = cipher.decrypt(ciphertext)
print(f"Decrypted text: {decrypted_text.decode()}")
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import padding
# Generate RSA keys
private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)
public_key = private_key.public_key()
# Encrypt data
plaintext = b"Secret message"
ciphertext = public_key.encrypt(
plaintext,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print(f"Ciphertext: {ciphertext}")
# Decrypt data
decrypted_text = private_key.decrypt(
ciphertext,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print(f"Decrypted text: {decrypted_text.decode()}")
import hashlib
# Hash data
data = b"Important data"
hash_object = hashlib.sha256(data)
hash_digest = hash_object.hexdigest()
print(f"SHA-256 Hash: {hash_digest}")
Cryptography is essential for securing communication and data in modern computing. Key concepts include plaintext, ciphertext, encryption, decryption, and keys. Cryptography is divided into symmetric and asymmetric key cryptography, with hash functions also playing a critical role. Applications of cryptography include secure communications, digital signatures, authentication, data integrity, and non-repudiation. Challenges in cryptography involve key management, cryptographic attacks, quantum computing threats, and performance overhead. The future of cryptography will focus on post-quantum cryptography and blockchain technologies.