Page 2 of 2

Posted: Thu May 19, 2011 12:31 pm
by satfreak666
Hmm ... I have coded the encoder-routine in Java. I can brute-force this message, but not the challange Message... am I missing something?

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;
    }
}
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

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

Posted: Thu May 19, 2011 12:58 pm
by Tron
Your text "This is a secret message" encoded with the key 11121314 and 3 rounds yields the cipher text: E30F49A6E649A6E648EC8C2824EC08660649A5ACEAE52EA8

It seems, that you are forming the eggs the wrong way round, i.e. first << 0, second << 8, third << 16, it should be first << 16, second << 8, third << 0.

Posted: Sat Jul 16, 2011 6:47 am
by whei
>> with the key 11121314 ...
so you mean key[0] == 0x11, key[1] == 0x12, ...
or is it the other way so you mean key[0] == 0x14, key[1] == 0x13, ... ???

Posted: Sat Aug 03, 2013 4:16 pm
by AgRaven
Oh man, this one is kicking my ass... I've loved the crypto challenges on this branch so far, no problems there, but I just can't figure out a sensible way to solve for the key without silly brute force (I'd love to understand rather than do that). Are any solvers still around who I can PM with my understanding and a question or two? Adum? I don't want to post my code/thoughts here; I think I'm somewhat close.

EDIT:

Cancel that, got it. :)

Posted: Mon Jun 04, 2018 5:37 pm
by one.kamila
Alright, admittedly, I'm very new to computer science and programming as a whole (I would say that I'm somewhat competent in only three languages, but not 100% fluent in all three). With that said, could someone please tell me what language the algorithm given to us in the prompt is written in? Or at least explain to me what this line (below) means:

Code: Select all

(key[eggs&0x3]<<8)
If I can figure out what that line means, or which language this is algorithm is written in, I know that I will be able to translate it into the few languages I know.

Any and all help is greatly appreciated! (And yes, I know that I should learn more languages. I am trying to, but life is very good at keeping people busy.)


EDIT: After doing some research, I was able to figure out what the specific line means. (Side note: looks like the code given is written in a language that I know, so I won't need to translate :D )

Posted: Fri Jun 22, 2018 3:25 pm
by one.kamila
Ok, I have two new questions, regarding two different lines of code.

1.

Code: Select all

key = {unknown four-byte value}
So, just to make sure that I'm understanding this correctly, key is an array containing four different bytes, correct? (i.e. key = {a4, 91, f0, b6})

2.

Code: Select all

for (int eggs = {each 3-byte tuple in plaintext})
I have two separate questions regarding this one.

1. Is the 3-byte tuple a string of three characters? (for example, would eggs = {38, 2d, 81})

2. Assuming that the above question is correct, do I need to convert each byte into an integer, or all three bytes into an integer?



I'm probably over thinking this, but I just want to make sure that I'm understanding this correctly.[/list]

Posted: Sat Jun 23, 2018 3:59 am
by eulerscheZahl
1. Not necessarily distinct, but in this case they are.
2.1 yes
2.2 keep the 3 bytes as an integer or you break the shifting logic. Your first egg is 3681665 in decimal

Posted: Sun Jun 24, 2018 6:07 am
by one.kamila
Perfect. Exactly what I needed. A response with (relatively*) specific answers, and even a slight example. THANK YOU!

*relative as in if you know what you were looking for

Posted: Mon Sep 30, 2019 4:33 pm
by one.kamila
Reading through this discussion board has confused me as to the nature of this line:

Code: Select all

for (int eggs = {each 3-byte tuple in plaintext}) 
Do I need to convert the entire tuple into one hex string, and then convert that hex string into an integer?
(i.e. if the tuple was: (0x38, 0x2d, 0x81), would eggs = int("382d81", 16)?)

Posted: Mon Sep 30, 2019 4:52 pm
by eulerscheZahl
Yes, that's what is meant with the tuples.

Posted: Sat Dec 26, 2020 5:15 pm
by Niker
Regarding what Tron said:
Tron wrote: Your text "This is a secret message" encoded with the key 11121314 and 3 rounds yields the cipher text: E30F49A6E649A6E648EC8C2824EC08660649A5ACEAE52EA8
I seem to be getting 6c8c8e29658e29658f630feeab6fcfe9858e2bafad6aad6e for the message "This is a secret message" and key = [11, 12, 13, 14].

Has anyone else managed to also obtain what Tron got?

Posted: Sat Dec 26, 2020 8:59 pm
by Niker
Realised I had my keys wrong, Tron is using [0x11, 0x12, 0x13, 0x14] which is [17, 18, 19, 20] in decimal.

Also, editing posts seems to throw a 500.