Posted: Thu May 19, 2011 12:31 pm
Hmm ... I have coded the encoder-routine in Java. I can brute-force this message, but not the challange Message... am I missing something?
Actually the Integer is being displaed in Big-Endian (human readable) Order. Otherwise you have to revert every 3rd Byte with evry 1st byte of a 3byte tupel.
The Output of the code is :
Code: Select all
package challanges;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
public class EggWarmUpPre
{
public static void main(String[] args) throws UnsupportedEncodingException
{
byte[] key = new byte[]
{ 0x11, 0x12, 0x13, 0x14 };
EggWarmUpPre eggWarmUpPre = new EggWarmUpPre();
byte[] encoded = eggWarmUpPre.encode("This is a secret message".getBytes("ASCII"), key);
byte[] encodedLeadingZero = new byte[encoded.length + 1];
System.arraycopy(encoded, 0, encodedLeadingZero, 1, encoded.length);
System.out.println("Encoded : " + new BigInteger(encodedLeadingZero).toString(16));
}
private byte[] encode(byte[] b, byte[] key)
{
int SCR_WIDTH = 24;
int SCR_LOOPS = 3;
byte[] result = new byte[b.length];
for (int j = 0; j < b.length; j += 3)
{
int i, roll = 7;
int eggs = 0;
eggs = (b[j] & 0xff) + ((b[j + 1] & 0xff) << 8) + ((b[j + 2] & 0xff) << 16);
for (i = 0; i < SCR_LOOPS; i++)
{
eggs ^= ((key[eggs & 0x3] & 0xff) << 8);
eggs = (eggs << roll) | (eggs >> (SCR_WIDTH - roll));
eggs &= ((1 << SCR_WIDTH) - 1);
}
System.out.println("encoding tupel to : " + Integer.toHexString(eggs));
result[j] = (byte) ((eggs >> 16) & 0xff);
result[j + 1] = (byte) ((eggs >> 8) & 0xff);
result[j + 2] = (byte) (eggs & 0xff);
}
return result;
}
}
The Output of the code is :
Code: Select all
encoding tupel to : c4af2e
encoding tupel to : 24268a
encoding tupel to : 25268a
encoding tupel to : c42c40
encoding tupel to : a5acc8
encoding tupel to : 45262a
encoding tupel to : 26ec28
encoding tupel to : e5aea8
Encoded : c4af2e24268a25268ac42c40a5acc845262a26ec28e5aea8