hacker.org Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Didactic Scrambled Egg Cipher Pre-Warmup Challenge
Goto page Previous  1, 2
 
Reply to topic    hacker.org Forum Index » Challenges View previous topic
View next topic
Didactic Scrambled Egg Cipher Pre-Warmup Challenge
Author Message
satfreak666



Joined: 16 May 2011
Posts: 11

Post Reply with quote
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:

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:

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

Thu May 19, 2011 12:31 pm View user's profile Send private message
Tron



Joined: 22 Oct 2010
Posts: 30

Post Reply with quote
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.
Thu May 19, 2011 12:58 pm View user's profile Send private message
whei



Joined: 04 Jul 2011
Posts: 1

Post Reply with quote
>> 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, ... ???
Sat Jul 16, 2011 6:47 am View user's profile Send private message
AgRaven



Joined: 24 Feb 2013
Posts: 13

Post Reply with quote
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. Smile
Sat Aug 03, 2013 4:16 pm View user's profile Send private message
one.kamila



Joined: 04 May 2018
Posts: 11

Post Reply with quote
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:
(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 Very Happy )
Mon Jun 04, 2018 5:37 pm View user's profile Send private message
one.kamila



Joined: 04 May 2018
Posts: 11

Post Reply with quote
Ok, I have two new questions, regarding two different lines of code.

1.

Code:
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:
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]
Fri Jun 22, 2018 3:25 pm View user's profile Send private message
eulerscheZahl



Joined: 29 Nov 2012
Posts: 56
Location: Germany

Post Reply with quote
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
Sat Jun 23, 2018 3:59 am View user's profile Send private message
one.kamila



Joined: 04 May 2018
Posts: 11

Post Reply with quote
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
Sun Jun 24, 2018 6:07 am View user's profile Send private message
one.kamila



Joined: 04 May 2018
Posts: 11

Post Reply with quote
Reading through this discussion board has confused me as to the nature of this line:
Code:
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)?)
Mon Sep 30, 2019 4:33 pm View user's profile Send private message
eulerscheZahl



Joined: 29 Nov 2012
Posts: 56
Location: Germany

Post Reply with quote
Yes, that's what is meant with the tuples.
Mon Sep 30, 2019 4:52 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    hacker.org Forum Index » Challenges All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.