Skip to content

Commit 3da8411

Browse files
committed
Read plaintext from input, indicate padding-only block
1 parent 9c52151 commit 3da8411

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Program.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ class PaddingOracleAttack
1111

1212
public static void Main()
1313
{
14-
string hiddenMessage = "I'd just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux.";
14+
Console.WriteLine("Enter plaintext:");
15+
string plaintext = Console.ReadLine();
1516

16-
byte[] encrypted = server.Encrypt(hiddenMessage);
17+
byte[] encrypted = server.Encrypt(plaintext);
1718
var blocks = sliceBytesIntoBlocks(encrypted);
1819

19-
Console.WriteLine("Plaintext:\n{0}", hiddenMessage);
20-
Console.WriteLine("\nCiphertext:\n{0}", String.Join("\n", blocks.ConvertAll(block => Convert.ToBase64String(block))));
21-
Console.WriteLine("\nAttack results:");
20+
Console.WriteLine("\nCiphertext blocks (base64):\n{0}", String.Join("\n", blocks.ConvertAll(block => Convert.ToBase64String(block))));
21+
Console.WriteLine("\nPadding oracle attack results:");
22+
Console.WriteLine("(first block cannot be decrypted)");
2223

2324
for (int blockIndex = 1; blockIndex < blocks.Count; ++blockIndex)
2425
{
25-
Console.WriteLine(DecryptBlock(blocks[blockIndex], blocks[blockIndex - 1]));
26+
string decryptedPlaintext = DecryptBlock(blocks[blockIndex], blocks[blockIndex - 1]);
27+
Console.WriteLine(decryptedPlaintext[0] != 16 ? decryptedPlaintext : "(padding-only block)");
2628
}
2729
}
2830

0 commit comments

Comments
 (0)