Challenge - 5 Problems
Data Encryption Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of AES encryption snippet
What is the output of this Unity C# code snippet that encrypts a string using AES and prints the Base64 result?
Unity
using System; using System.Security.Cryptography; using System.Text; public class EncryptTest { public static void Main() { string original = "hello"; byte[] key = Encoding.UTF8.GetBytes("1234567890123456"); byte[] iv = Encoding.UTF8.GetBytes("abcdefghijklmnop"); using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); byte[] originalBytes = Encoding.UTF8.GetBytes(original); byte[] encrypted = encryptor.TransformFinalBlock(originalBytes, 0, originalBytes.Length); Console.WriteLine(Convert.ToBase64String(encrypted)); } } }
Attempts:
2 left
💡 Hint
Look at how AES encryption transforms the input bytes and outputs a Base64 string.
✗ Incorrect
The code encrypts the string "hello" with AES using the given key and IV, then prints the encrypted bytes as Base64. Option B matches the expected Base64 output. Option B is a common OpenSSL prefix but not produced here. Option B is invalid syntax. Option B is the original string, not encrypted.
🧠 Conceptual
intermediate1:30remaining
Understanding symmetric vs asymmetric encryption
Which statement correctly describes the difference between symmetric and asymmetric encryption?
Attempts:
2 left
💡 Hint
Think about how keys are used in each encryption type.
✗ Incorrect
Symmetric encryption uses the same secret key to encrypt and decrypt data. Asymmetric encryption uses a public key to encrypt and a private key to decrypt. Option A correctly states this difference. Option A reverses the key usage. Option A is generally false; symmetric is faster. Option A is incorrect; asymmetric encryption is used for encrypting data.
🔧 Debug
advanced2:00remaining
Identify the error in this encryption code
What error will this Unity C# code produce when run?
Unity
using System; using System.Security.Cryptography; using System.Text; public class EncryptDebug { public static void Main() { string text = "data"; byte[] key = Encoding.UTF8.GetBytes("shortkey"); byte[] iv = Encoding.UTF8.GetBytes("shortiv"); using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); byte[] bytes = Encoding.UTF8.GetBytes(text); byte[] encrypted = encryptor.TransformFinalBlock(bytes, 0, bytes.Length); Console.WriteLine(Convert.ToBase64String(encrypted)); } } }
Attempts:
2 left
💡 Hint
Check the length of the key and IV for AES requirements.
✗ Incorrect
AES requires keys of specific lengths (128, 192, or 256 bits). The provided key and IV are too short (8 bytes each). This causes a CryptographicException about invalid key size. Option C is incorrect because aes is properly created. Option C is Base64 of "data" (no encryption). Option C is not triggered here.
📝 Syntax
advanced2:00remaining
Which code snippet correctly decrypts AES data?
Which of the following Unity C# code snippets correctly decrypts AES encrypted data stored in a byte array named encryptedData?
Attempts:
2 left
💡 Hint
Check the method used to create the decryptor and the order of parameters.
✗ Incorrect
Option D correctly uses CreateDecryptor with key and IV in correct order. Option D incorrectly uses CreateEncryptor for decryption. Option D calls CreateDecryptor without parameters, which uses default key and IV (likely incorrect). Option D swaps key and IV parameters, causing wrong decryption or error.
🚀 Application
expert2:30remaining
Calculate the length of encrypted data
Given a plaintext string of length 30 bytes encrypted with AES in CBC mode with PKCS7 padding, what is the length in bytes of the encrypted output?
Attempts:
2 left
💡 Hint
AES block size is 16 bytes. PKCS7 padding adds bytes to fill the last block.
✗ Incorrect
AES block size is 16 bytes. The plaintext is 30 bytes, which is 1 full block (16 bytes) plus 14 bytes. PKCS7 padding adds 2 bytes to fill the last block to 16 bytes. So total encrypted length is 32 bytes (2 blocks). Option A is correct. Option A ignores padding. Option A is too large. Option A is just one block size.