Didactic Scrambled Egg Cipher Pre-Warmup Challenge

satfreak666
Posts: 11
Joined: Mon May 16, 2011 8:37 am

Post 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
Tron
Posts: 30
Joined: Fri Oct 22, 2010 6:59 pm

Post 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.
whei
Posts: 1
Joined: Mon Jul 04, 2011 8:19 am

Post 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, ... ???
AgRaven
Posts: 13
Joined: Sun Feb 24, 2013 8:27 am

Post 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. :)
one.kamila
Posts: 11
Joined: Fri May 04, 2018 4:21 pm

Post 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 )
one.kamila
Posts: 11
Joined: Fri May 04, 2018 4:21 pm

Post 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]
eulerscheZahl
Posts: 58
Joined: Thu Nov 29, 2012 7:45 pm
Location: Germany

Post 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
one.kamila
Posts: 11
Joined: Fri May 04, 2018 4:21 pm

Post 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
one.kamila
Posts: 11
Joined: Fri May 04, 2018 4:21 pm

Post 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)?)
eulerscheZahl
Posts: 58
Joined: Thu Nov 29, 2012 7:45 pm
Location: Germany

Post by eulerscheZahl »

Yes, that's what is meant with the tuples.
User avatar
Niker
Posts: 9
Joined: Sun Jun 15, 2014 4:42 am

Post 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?
do the lala
User avatar
Niker
Posts: 9
Joined: Sun Jun 15, 2014 4:42 am

Post 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.
do the lala
Post Reply