×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

Practice Cryptography with Python MCQs (Multiple-Choice Questions)

Cryptography with Python involves using Python libraries and cryptographic packages to protect data, verify integrity, authenticate messages, generate secure secrets, derive cryptographic keys, and perform encryption and decryption. Python provides standard modules such as hashlib, hmac, and secrets, while the cryptography package provides higher-level recipes and lower-level cryptographic primitives.

Practice Cryptography with Python MCQs

These Practice Cryptography with Python multiple-choice questions cover important concepts such as hashing, SHA-256, HMAC, secure random numbers, Fernet, symmetric encryption, authenticated encryption, key derivation, RSA, elliptic-curve cryptography, digital signatures, certificates, and Python cryptographic libraries. Practice these MCQs to test and improve your knowledge of cryptography with Python.

List of Practice Cryptography with Python MCQs

Here is a list of Practice Cryptography with Python MCQs with answers and explanations.

1. What is cryptography primarily used for?

  1. Increasing program execution speed
  2. Protecting information and enabling secure communication
  3. Managing Python packages
  4. Creating database tables

Answer: B) Protecting information and enabling secure communication

Explanation:

Cryptography provides techniques for protecting information, including confidentiality, integrity, authentication, and digital signatures.

2. Which standard Python module provides secure hash algorithms?

  1. hashlib
  2. crypto
  3. hash
  4. securehash

Answer: A) hashlib

Explanation:

The Python hashlib module provides a common interface to several secure hash algorithms and message digests.

3. Which of the following is a cryptographic hash algorithm available through hashlib?

  1. SHA-256
  2. HTTP
  3. FTP
  4. JSON

Answer: A) SHA-256

Explanation:

hashlib provides secure hash algorithms including SHA-224, SHA-256, SHA-384, SHA-512, and SHA-3 variants.

4. Which function creates a SHA-256 hash object?

  1. hashlib.sha256()
  2. hashlib.sha_256()
  3. hashlib.create_sha256()
  4. hashlib.hash256()

Answer: A) hashlib.sha256()

Explanation:

The hashlib.sha256() constructor creates a SHA-256 hash object that can receive data through methods such as update().

5. Which method adds data to a hashlib hash object?

  1. update()
  2. append()
  3. add()
  4. insert()

Answer: A) update()

Explanation:

The update() method feeds additional bytes into a hash object. Multiple calls are equivalent to hashing the concatenation of the supplied data.

6. Which method returns the raw binary digest of a hash object?

  1. digest()
  2. binary()
  3. raw()
  4. bytes()

Answer: A) digest()

Explanation:

The digest() method returns the hash digest as a bytes object.

7. Which method returns a hash digest as hexadecimal characters?

  1. hexdigest()
  2. hex()
  3. hexadecimal()
  4. digest_hex()

Answer: A) hexdigest()

Explanation:

The hexdigest() method returns the digest as a string containing hexadecimal digits.

8. What is a major property of a cryptographic hash function?

  1. It is designed to produce a fixed-size digest from input data
  2. It always produces encrypted plaintext
  3. It can always be reversed to recover the original input
  4. It requires a public key

Answer: A) It is designed to produce a fixed-size digest from input data

Explanation:

Cryptographic hash functions map input data to a fixed-size digest. They are designed to make recovering the original input or finding useful collisions computationally difficult.

9. Which statement about cryptographic hashing is correct?

  1. Hashing is normally designed to be reversible
  2. Hashing and encryption are identical
  3. Hashing is generally a one-way operation
  4. Hashing always requires a secret key

Answer: C) Hashing is generally a one-way operation

Explanation:

Cryptographic hashes are designed as one-way functions. Unlike encryption, they are not intended to provide a method for recovering the original message from the digest.

10. Which hash algorithm belongs to the SHA-2 family?

  1. SHA-256
  2. MD5
  3. SHA-3
  4. BLAKE2

Answer: A) SHA-256

Explanation:

SHA-256 is a member of the SHA-2 family of cryptographic hash functions.

11. Which standard Python module is specifically designed to generate cryptographically strong random numbers?

  1. secrets
  2. random
  3. randcrypto
  4. secure_random

Answer: A) secrets

Explanation:

The secrets module is intended for generating cryptographically strong random numbers suitable for managing secrets such as tokens.

12. Why should the secrets module be preferred over random for security-sensitive random values?

  1. It generates floating-point numbers faster
  2. It is designed specifically for cryptographically strong randomness
  3. It uses fewer CPU instructions
  4. It automatically encrypts files

Answer: B) It is designed specifically for cryptographically strong randomness

Explanation:

The secrets module is intended for security-sensitive applications. The regular random module is not designed for cryptographic security.

13. Which function can generate a cryptographically secure random hexadecimal token?

  1. secrets.token_hex()
  2. secrets.hex_random()
  3. secrets.random_hex()
  4. secrets.secure_hex()

Answer: A) secrets.token_hex()

Explanation:

secrets.token_hex() generates a random text string containing hexadecimal characters suitable for security-sensitive token generation.

14. Which function generates a URL-safe random token?

  1. secrets.token_urlsafe()
  2. secrets.url_token()
  3. secrets.safe_url()
  4. secrets.web_token()

Answer: A) secrets.token_urlsafe()

Explanation:

secrets.token_urlsafe() generates a random token encoded using a URL-safe representation.

15. Which module implements HMAC in the Python standard library?

  1. hmac
  2. mac
  3. hashmac
  4. messageauth

Answer: A) hmac

Explanation:

The Python hmac module implements the HMAC algorithm for message authentication using a secret key and a cryptographic hash function.

16. What does HMAC primarily provide?

  1. Message authentication and integrity
  2. Compression
  3. Database indexing
  4. Image encryption only

Answer: A) Message authentication and integrity

Explanation:

HMAC combines a secret key with a hash function to produce an authentication code that can be used to verify message integrity and authenticity.

17. Which function creates an HMAC object?

  1. hmac.new()
  2. hmac.create()
  3. hmac.make()
  4. hmac.generate()

Answer: A) hmac.new()

Explanation:

The hmac.new() function creates a new HMAC object. A digest algorithm must be specified using the digestmod parameter.

18. Which function is recommended for securely comparing HMAC values?

  1. hmac.compare_digest()
  2. hmac.safe_compare()
  3. hmac.secure_equal()
  4. hmac.verify()

Answer: A) hmac.compare_digest()

Explanation:

hmac.compare_digest() is designed to reduce the risk of timing attacks when comparing authentication values.

19. Which cryptographic operation transforms plaintext into ciphertext?

  1. Encryption
  2. Hashing
  3. Verification
  4. Digesting

Answer: A) Encryption

Explanation:

Encryption transforms plaintext into ciphertext using a cryptographic algorithm and key. Decryption reverses this process when the appropriate key and parameters are available.

20. What is symmetric encryption?

  1. Encryption using the same secret key for encryption and decryption
  2. Encryption using only public keys
  3. Hashing without a key
  4. Encryption using two unrelated passwords

Answer: A) Encryption using the same secret key for encryption and decryption

Explanation:

Symmetric encryption uses a shared secret key for both encryption and decryption.

21. Which Python package provides the Fernet symmetric encryption recipe?

  1. cryptography
  2. hashlib
  3. secrets
  4. sslcrypto

Answer: A) cryptography

Explanation:

The pyca/cryptography package provides the high-level Fernet recipe for symmetric encryption.

22. Which class is used for Fernet encryption?

  1. Fernet
  2. SymmetricCipher
  3. FernetCipher
  4. SecureFernet

Answer: A) Fernet

Explanation:

The Fernet class provides a high-level symmetric authenticated encryption recipe in the cryptography package.

23. Which method generates a new Fernet key?

  1. Fernet.generate_key()
  2. Fernet.create_key()
  3. Fernet.new_key()
  4. Fernet.random_key()

Answer: A) Fernet.generate_key()

Explanation:

Fernet.generate_key() generates a new key suitable for use with Fernet.

24. Which method encrypts data using a Fernet object?

  1. encrypt()
  2. encode()
  3. secure()
  4. protect()

Answer: A) encrypt()

Explanation:

The encrypt() method encrypts a bytes-like plaintext value using the Fernet key.

25. Which method decrypts a Fernet token?

  1. decrypt()
  2. decode()
  3. unlock()
  4. restore()

Answer: A) decrypt()

Explanation:

The decrypt() method decrypts a Fernet token and returns the original plaintext when the token is valid and the correct key is supplied.

26. What happens if an invalid Fernet token is supplied for decryption?

  1. An InvalidToken exception can be raised
  2. The token is automatically repaired
  3. The plaintext is returned unchanged
  4. The key is regenerated automatically

Answer: A) An InvalidToken exception can be raised

Explanation:

The cryptography package provides InvalidToken for situations where a Fernet token is invalid, expired when a time limit is used, or otherwise cannot be authenticated.

27. What is authenticated encryption?

  1. Encryption that also provides authentication or integrity protection
  2. Encryption without a key
  3. Hashing followed by compression
  4. Encryption that only changes character encoding

Answer: A) Encryption that also provides authentication or integrity protection

Explanation:

Authenticated encryption protects confidentiality while also providing a mechanism to detect unauthorized modification of ciphertext and associated data when supported.

28. Which of the following is an authenticated encryption algorithm supported by the cryptography package?

  1. AESGCM
  2. AESPlain
  3. SimpleAES
  4. AESHash

Answer: A) AESGCM

Explanation:

AESGCM is an authenticated encryption construction provided by the cryptography package.

29. What does AEAD stand for?

  1. Authenticated Encryption with Associated Data
  2. Advanced Encryption and Data
  3. Authenticated Encoding and Decryption
  4. Automatic Encryption with Digital Data

Answer: A) Authenticated Encryption with Associated Data

Explanation:

AEAD stands for Authenticated Encryption with Associated Data. It provides confidentiality and authentication for encrypted data while allowing additional associated data to be authenticated without being encrypted.

30. Which cipher is commonly used as an authenticated encryption mode when implemented as AES-GCM?

  1. AES
  2. DES
  3. RC4
  4. Caesar cipher

Answer: A) AES

Explanation:

AES-GCM combines the AES block cipher with Galois/Counter Mode to provide authenticated encryption.

31. What is asymmetric cryptography?

  1. A cryptographic system using a related public key and private key
  2. A system using only one shared password
  3. A hashing algorithm without keys
  4. A method of compressing encrypted files

Answer: A) A cryptographic system using a related public key and private key

Explanation:

Asymmetric cryptography uses a key pair consisting of a public key and a corresponding private key. Different operations use the keys according to the cryptographic scheme.

32. Which algorithm is an asymmetric cryptographic algorithm?

  1. RSA
  2. SHA-256
  3. HMAC
  4. SHA-3

Answer: A) RSA

Explanation:

RSA is an asymmetric cryptographic algorithm that uses a public key and a private key.

33. Which Python package provides RSA primitives through its cryptography.hazmat layer?

  1. cryptography
  2. hashlib
  3. secrets
  4. random

Answer: A) cryptography

Explanation:

The cryptography package provides RSA functionality in its low-level primitives layer under cryptography.hazmat.

34. Which function can generate a new RSA private key in the cryptography package?

  1. rsa.generate_private_key()
  2. rsa.create_key()
  3. rsa.new_private_key()
  4. rsa.generate_keypair()

Answer: A) rsa.generate_private_key()

Explanation:

The cryptography package provides rsa.generate_private_key() for generating RSA private keys.

35. What is a digital signature primarily used for?

  1. Authenticating data and detecting unauthorized modification
  2. Compressing files
  3. Generating database indexes
  4. Replacing all encryption

Answer: A) Authenticating data and detecting unauthorized modification

Explanation:

Digital signatures can provide evidence that data was signed by the holder of a private key and that the signed data has not been modified.

36. Which key is normally used to create a digital signature?

  1. Private key
  2. Public key
  3. Hash key only
  4. Session identifier

Answer: A) Private key

Explanation:

In public-key signature systems, the signer uses a private key to create the signature. The corresponding public key can be used to verify it.

37. Which key is normally used to verify a digital signature?

  1. Public key
  2. Private key
  3. Session key
  4. Hash digest

Answer: A) Public key

Explanation:

The corresponding public key is normally distributed to parties that need to verify a signature created with the private key.

38. Which cryptographic algorithm is designed for elliptic-curve digital signatures?

  1. Ed25519
  2. SHA-256
  3. AES-GCM
  4. HMAC-SHA256

Answer: A) Ed25519

Explanation:

Ed25519 is a public-key signature algorithm based on elliptic-curve cryptography and is supported by the cryptography package.

39. Which cryptographic mechanism is commonly used for key agreement?

  1. Diffie-Hellman
  2. SHA-256
  3. HMAC
  4. MD5

Answer: A) Diffie-Hellman

Explanation:

Diffie-Hellman is a key agreement method that allows parties to establish shared secret material over an insecure communication channel.

40. Which elliptic-curve algorithm is designed for key exchange in the cryptography package?

  1. X25519
  2. SHA25519
  3. AES25519
  4. HMAC25519

Answer: A) X25519

Explanation:

X25519 is an elliptic-curve key exchange algorithm supported by the cryptography package.

41. What is a salt in password-based key derivation?

  1. Additional random data used with a password-derived key process
  2. The encryption key itself
  3. A compressed password
  4. A digital certificate

Answer: A) Additional random data used with a password-derived key process

Explanation:

A salt is additional data used during password hashing or key derivation. A unique salt helps prevent attackers from efficiently reusing precomputed results across users or passwords.

42. Which Python hashlib function implements PBKDF2 using HMAC?

  1. hashlib.pbkdf2_hmac()
  2. hashlib.password_key()
  3. hashlib.derive_key()
  4. hashlib.pbkdf()

Answer: A) hashlib.pbkdf2_hmac()

Explanation:

hashlib.pbkdf2_hmac() implements the PBKDF2 key derivation function using HMAC as its pseudorandom function.

43. Why are password-based key derivation functions designed to be computationally expensive?

  1. To make large-scale password guessing more expensive
  2. To increase file size
  3. To make encryption reversible
  4. To remove the need for salts

Answer: A) To make large-scale password guessing more expensive

Explanation:

Password-based key derivation functions are designed to be tunable and relatively expensive so that brute-force and password-guessing attacks become more costly.

44. What is the purpose of X.509 certificates?

  1. To represent and authenticate identities using public-key certificates
  2. To compress passwords
  3. To replace hash functions
  4. To store Python source code

Answer: A) To represent and authenticate identities using public-key certificates

Explanation:

X.509 certificates are widely used in public-key infrastructures to bind identities to public keys and support certificate-based authentication.

45. Which Python package provides X.509 certificate functionality in the cryptography ecosystem?

  1. cryptography
  2. hashlib
  3. secrets
  4. hmac

Answer: A) cryptography

Explanation:

The cryptography package includes APIs for creating, loading, parsing, and working with X.509 certificates.

46. Which statement about the cryptography package's hazmat layer is correct?

  1. It contains low-level cryptographic primitives that require careful use
  2. It is only used for random numbers
  3. It contains no cryptographic algorithms
  4. It is designed only for formatting HTML

Answer: A) It contains low-level cryptographic primitives that require careful use

Explanation:

The cryptography package separates high-level recipes from low-level primitives. The low-level APIs are located under the hazmat namespace and require more cryptographic knowledge and careful configuration.

47. Which approach does the cryptography documentation recommend when possible?

  1. Use high-level recipes rather than low-level primitives when appropriate
  2. Always implement encryption algorithms manually
  3. Never use authenticated encryption
  4. Always use deprecated algorithms

Answer: A) Use high-level recipes rather than low-level primitives when appropriate

Explanation:

The cryptography documentation recommends using its high-level recipes whenever possible because they reduce the number of cryptographic configuration decisions developers must make.

48. Which statement about passwords and encryption is correct?

  1. Passwords should normally be stored in recoverable encrypted form
  2. Passwords should normally be stored using an appropriate password hashing or key derivation approach rather than recoverable encryption
  3. Passwords should always be stored as plain text
  4. Passwords do not require salts

Answer: B) Passwords should normally be stored using an appropriate password hashing or key derivation approach rather than recoverable encryption

Explanation:

Password storage should use an appropriate password hashing or key derivation scheme rather than storing passwords in a recoverable form. Python documentation specifically notes that applications should not store passwords in recoverable form.

49. Which algorithm is generally considered unsuitable for new cryptographic security designs because of collision weaknesses?

  1. MD5
  2. SHA-256
  3. SHA-384
  4. SHA-512

Answer: A) MD5

Explanation:

MD5 has known collision weaknesses and should not be selected for applications that require modern cryptographic collision resistance. Modern applications should use an appropriate stronger algorithm for their security requirements.

50. Which statement best describes cryptography with Python?

  1. Python provides only hashing and no other cryptographic functionality
  2. Python provides standard cryptographic utilities and can use specialized packages for encryption, authentication, key management, and certificates
  3. Python automatically encrypts every variable
  4. Python cryptography is limited to password generation

Answer: B) Python provides standard cryptographic utilities and can use specialized packages for encryption, authentication, key management, and certificates

Explanation:

Python's standard library includes modules such as hashlib, hmac, and secrets. The widely used cryptography package extends Python with high-level recipes and low-level primitives for modern cryptographic applications.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2026 www.includehelp.com. All rights reserved.