patterns in ciphertext

V

vaneric

i was trying out some code to demonstrate that patterns in plaintext
cause patterns to appear in ciphertext when ECB is used for encrypt/
decrypt operations.I used bountycastle as provider.
I used DES and AES as the cipher algorithms and gave proper length
keybytes for creating SecretKeySpec.

i used an input byte[] as plaintext and another byte[] for creating
SecretKeySpec as below

byte[] input = new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
byte[]keyBytes = new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};//DES key
SecretKeySpec key = new SecretKeySpec(keyBytes, "DES");

Cipher cipher = Cipher.getInstance("DES/ECB/PKCS7Padding", "BC");
System.out.println("input : " + Utils.toHex(input,input.length));
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText =new byte[cipher.getOutputSize(input.length)];
int ctLength =cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
System.out.println("cipher: " + Utils.toHex(cipherText, ctLength)+ "
bytes: " + ctLength);


----------------------
i used a toHex(byte[]data,int length) method to print the hex of a byte
[]
public static String toHex(byte[] data, int length) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i != length; i++)
{
int v = data & 0xff;
buf.append(digits.charAt(v >> 4));
buf.append(digits.charAt(v & 0xf));
}
return buf.toString();
}[/QUOTE][/QUOTE]
input : 000102030405060708090a0b0c0d0e0f0001020304050607
cipher:
e1b246e5a7c74cbc92c9db45300b932fe1b246e5a7c74cbce481a8d39714d0de
bytes: 32

Here the pattern is evident.The plaintext block 0001020304050607
causes the pattern e1b246e5a7c74cbc in ciphertext.

Then i tried the same with AES providing keybytes of
byte[]keyBytes = new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };

and creating
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");

then the program createdinput : 000102030405060708090a0b0c0d0e0f0001020304050607
cipher:
0060bffe46834bb8da5cf9a61ff220ae5cbbd8811851a91781d5d358213579fe
bytes: 32

Here i couldn't find the patterns in ciphertext eventhough i am using
ECB.
Can someone explain this?I am a beginner in this field and so
understand little of the mechanisms.
thanks
eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top