mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 309
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
Could this post be any less related to mIRC? Well; lets see. I could talk about zebras.

Now; intrepid C coders; I am doing a course. That course features some rather nasty lecturers. Occasionally we get something fun. I thought this was both fun and hard; I sitll haven't pulled it all to bits in my head (I don't know all of the keys; which was required; but I got both messages.)
Note: Every C/C++ room I tried to get help in more or less told me "your program is a pile of dog crap". They couldn't or wouldn't grasp the concept of a program that's not meant to work.
On with the show.
---
You have just intercepted an encoded message. The message is a sequence of bits which reads as follows in hexadecimal:

6363636363636363724646636F6D6F72
466D203A65693A7243646E206F54540A
5920453A54756F0A6F6F470A21643A6F
594E2020206F776F797275744563200A
6F786F686E6963736C206765796C656B
2C3365737420346E20216F74726F5966
7565636F202061206C61676374206C6F
20206F74747865656561727632727463
6E617920680A64746F69766120646E69
21687467630020656C6C786178742078
6578206F727478787863617800783174

You have no idea how to decode it, but you know that your grade depends on it, so you are willing to do anything to extract the message. Fortunately, one of your many agents on the field has stolen the source code for the decoder. This agent (007) has put the code and the message in the file secret.cpp.

Q has noticed that the decoder takes four integers as arguments. Executing the decoder with various arguments seems to either crash the program or produce unintelligible output. It seems that the correct four integers have to be chosen in order for the program to produce the decoded message. These four integers are the "secret keys."

007 has been unable to find the keys, but from the desk of the encrypting personnel he was able to cunningly retrieve the first five characters of the unencoded message. These characters are:

From:

Assignment
Your assignment is to decode the message, and find the keys.

This exercise is not extremely difficult. However, the strategy of trying things until something works will be ineffective. Try to understand the material in the course, particularly the following:

Strategy
The designers of this decoder weren't very good. They made it possible for us to attack the keys in two independent parts. Try to break the first two keys first, and do not try to break the third and fourth keys until you have succeeded with the first two.
---
#include <stdio.h>
#include <stdlib.h>

int prologue [] = {
0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F,
0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,
0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,
0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,
0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,
0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,
0x20206F74, 0x74786565, 0x65617276, 0x32727463,
0x594E2020, 0x206F776F, 0x79727574, 0x4563200A
};

int data [] = {
0x63636363, 0x63636363, 0x72464663, 0x6F6D6F72,
0x466D203A, 0x65693A72, 0x43646E20, 0x6F54540A,
0x5920453A, 0x54756F0A, 0x6F6F470A, 0x21643A6F,
0x594E2020, 0x206F776F, 0x79727574, 0x4563200A,
0x6F786F68, 0x6E696373, 0x6C206765, 0x796C656B,
0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,
0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,
0x20206F74, 0x74786565, 0x65617276, 0x32727463,
0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,
0x21687467, 0x63002065, 0x6C6C7861, 0x78742078,
0x6578206F, 0x72747878, 0x78636178, 0x00783174
};

int epilogue [] = {
0x594E2020, 0x206F776F, 0x79727574, 0x4563200A,
0x6E617920, 0x680A6474, 0x6F697661, 0x20646E69,
0x7565636F, 0x20206120, 0x6C616763, 0x74206C6F,
0x2C336573, 0x7420346E, 0x20216F74, 0x726F5966,
0x20206F74, 0x74786565, 0x65617276, 0x32727463
};

char message[100];

void usage_and_exit(char * program_name) {
fprintf(stderr, "USAGE: %s key1 key2 key3 key4\n", program_name);
exit(1);
}

void process_keys12 (int * key1, int * key2) {

*((int *) (key1 + *key1)) = *key2;
}

void process_keys34 (int * key3, int * key4) {

*(((int *)&key3) + *key3) += *key4;
}

char * extract_message1(int start, int stride) {
int i, j, k;
int done = 0;

for (i = 0, j = start + 1; ! done; j++) {
for (k = 1; k < stride; k++, j++, i++) {

if (*(((char *) data) + j) == '\0') {
done = 1;
break;
}

message[i] = *(((char *) data) + j);
}
}
message[i] = '\0';
return message;
}


char * extract_message2(int start, int stride) {
int i, j;

for (i = 0, j = start;
*(((char *) data) + j) != '\0';
i++, j += stride)
{
message[i] = *(((char *) data) + j);
}
message[i] = '\0';
return message;
}

int main (int argc, char *argv[])
{
int dummy = 1;
int start, stride;
int key1, key2, key3, key4;
char * msg1, * msg2;

key3 = key4 = 0;
if (argc < 3) {
usage_and_exit(argv[0]);
}
key1 = strtol(argv[1], NULL, 0);
key2 = strtol(argv[2], NULL, 0);
if (argc > 3) key3 = strtol(argv[3], NULL, 0);
if (argc > 4) key4 = strtol(argv[4], NULL, 0);

process_keys12(&key1, &key2);

start = (int)(*(((char *) &dummy)));
stride = (int)(*(((char *) &dummy) + 1));

if (key3 != 0 && key4 != 0) {
process_keys34(&key3, &key4);
}

msg1 = extract_message1(start, stride);

if (*msg1 == '\0') {
process_keys34(&key3, &key4);
msg2 = extract_message2(start, stride);
printf("%s\n", msg2);
}
else {
printf("%s\n", msg1);
}

return 0;
}

---
I was heaps proud to be able to do most of the work using nothing more than Borland's free command line tools. HURRAH!
If you manage to work out all the keys; I'll prolly pester you for an explanation of key2 as no one has of yet been able to explain it too well.

Last edited by ParaBrat; 11/08/03 04:14 PM.
#40378 07/08/03 04:43 PM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
It's a stereogram. You stare at it long enough, and the key is revealed to you.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#40379 07/08/03 08:22 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Is it just me, or is anyone getting casting errors...


-KingTomato
#40380 07/08/03 08:25 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
The casting he has in that program is atrocious, once I saw how much casting he has there, I just decided not to bother.

#40381 07/08/03 08:26 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
lol--tell me about it..

I think its all part of the scheme of making it more difficult. First you have to debug his program THEN try it.. lol

EDIT: I have an exe if you want it. Got it to finally compile >:D


-KingTomato
#40382 07/08/03 09:20 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
w00h00, first line...

From: CTE


-KingTomato
#40383 11/08/03 04:12 PM
Joined: Dec 2002
Posts: 3,127
P
Hoopy frood
Offline
Hoopy frood
P
Joined: Dec 2002
Posts: 3,127
I have reopened this thread even tho it isnt mIRC related with the provisions that
1: we arent here to do someone's homework
2: no flames/insults/bickering

If anyone wishes to play with this and aim CloCkWeRX in the
right direction to solve it himself, fine. Even tho it isnt really suited to this forum, it may entertain some of you and be a learning experience for others so what the heck. This time, so dont make a habit of it CloCkWeRX :tongue:


ParaBrat @#mIRCAide DALnet
#40384 11/08/03 07:06 PM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
>:D

Quote:

From: CTE
To: You
Excellent! You got everything!


Might i suggest the debug feature in VC++ >:D Get the memory address of dummy as it is beging referenced here:

start = (int)(*(((char *) &dummy)));


-KingTomato
#40385 13/08/03 12:12 AM
Joined: Feb 2003
Posts: 309
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Feb 2003
Posts: 309
Ah hah. Well ; I had both messages but I just don't know the dealio with key2.

I figure that some loss of precision is going on somewhere with it - I just don't know what command line argument to supply so that stride is correctly set to 3.
If you get it wrong you notice the value is set to 0 provided the number is small enough.

Key1 is simple enough; as you need to set &dummy = *key2, and processkeys12() evaluates key1 + &key1 and makes a funky pointer which would happen to make &dummy be the target majiggie.

Stride has to be set to 3.
Start has to be... uhmn... 9, wasn't it (I can't remember)

But whats happening with key2, eh?
What value will work so that it loses precision just enough to be 3?
I thought 12; but I was thinking in binary. About then I got in a terrible mess and gave up a little.
If you know the value please don't actually mention; just some hints would be nice. Now I have to go collapse and sleep.


Link Copied to Clipboard