Obfuscate Code Contest 5 - Results Poll

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Postby gamma » Mon Dec 20, 2004 4:30 am

exomo wrote:ps: where is gamma? I allways liked his code.

Hey, I have a fan! 8). No time this time. I spend one day interpreting code from others from contest 4 and I finished mathschallenge.net/euler to 100%. In other words: I spent my spare time elsewhere this time. (This reminds me that I still have to vote in contest 4... :oops:)

I'll try to enter the next obfuscated contest (although the contest is not obfuscated... I think it should be obfuscating contest.)
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Darobat » Mon Dec 20, 2004 9:40 am

I updated the polls and changed Mattxl's entry so it works properly now. Sorry, I wasn't able to do much yesterday.
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Postby Corsix » Mon Dec 20, 2004 10:20 am

I vote Exomo and Beer Hunter
PS. gamma - cud u plz 'decode' Beer Hunter's - it makes my head hurt
Code: Select all
#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}
User avatar
Corsix
 
Posts: 1181
Joined: Fri Jul 23, 2004 9:33 am
Location: Berkeley, UK

Postby gamma » Mon Dec 20, 2004 10:48 am

Corsix wrote:I vote Exomo and Beer Hunter
PS. gamma - cud u plz 'decode' Beer Hunter's - it makes my head hurt
Sounds like a real challenge as I have not participated in this contest. Sounds like a good evening filler 8). I'll have to skip StarTrek Enterprise though :wink:
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby exomo » Mon Dec 20, 2004 11:27 am

(although the contest is not obfuscated... I think it should be obfuscating contest.)


That's why I call it obfiscated code contest.

@ gamma: I tried to decrypt your code for the last contest, but I couldn't get it; it's just too good (or should I say bad :roll: )
Another one who has 100% @ mathchallenge, it's scary. But I have done the last one, too, it was not that hard as they said.

btw: I solved the ones "find the way through the matrix" using a modified version of the labyrinth-finder I did for OCC 4.

And: I'd like my vote from myself to Beer Hunter. Very nice program (works now) and as allways much more than we had to do. So Mattxl and BeerHunter have my votes
Who needs a signature anyway.
User avatar
exomo
 
Posts: 880
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Postby gamma » Mon Dec 20, 2004 12:29 pm

exomo wrote:
(although the contest is not obfuscated... I think it should be obfuscating contest.)

That's why I call it obfiscated code contest.
Very true. I should learn to read someday :oops:

exomo wrote:@ gamma: I tried to decrypt your code for the last contest, but I couldn't get it; it's just too good (or should I say bad :roll: )
:twisted:. I'll take that is a compliment then.

exomo wrote:Another one who has 100% @ mathchallenge, it's scary. But I have done the last one, too, it was not that hard as they said.
Last one was easy. Definately. Most of them are actually. The last ones I had to solve involved writing longer programs, not necessarily more difficult. With some, I "cheated" as in used Mathematica, most where straight forward c-style C++-programs though. If you need a hint somewhere, I can be of assistence, too. Kept all me programs.

I'll start the Beerhunter decryption now.
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby gamma » Mon Dec 20, 2004 1:09 pm

20:10, indenting done:
Hmm, my first impression of Beerhunter technique:
using streambufs to obfuscate his actual strings.
Can't compile with my g++:
Code: Select all
beerhunter5.cc: In constructor `cs::cs()':
beerhunter5.cc:222: no matching function for call to `cs::setp(int, int, int)'
/usr/include/g++-v3/bits/std_streambuf.h:428: candidates are: void
   std::basic_streambuf<_CharT, _Traits>::setp(_CharT*, _CharT*) [with _CharT = char, _Traits = std::char_traits<char>]

21:10, setp(0,0) seems to work just fine. Decryption progresses smoothly. This will be cracked soon.
22:10, I'm off to bed. This is what I have sofar: http://www.fmf.nl/~dopheide/darobat/beerhunter5.cc
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Beer Hunter » Tue Dec 21, 2004 12:55 am

Eh, I'll just tell you how it works.

struct T is a tokeniser class. It takes a string and breaks it up on boundaries defined by spaces and exclamation marks. I modelled it after an input iterator (hence the apparently bogus typedefs). The equality operator merely returns true if both T objects have reached the end of tokenisation. Also, a default-constructed T object is automatically 'at the end'.

I do the actual incrementation in operator * for the obfuscated fun of it.

Next, I use the T class to map all the words in 'foo' to all the words in 'bar'. This is used later for output.

class cs is a stream buffer. At the beginning of execution, I replace cout's buffer with a cs object, allowing me to receive each individual character sent to cout. I accumulate these characters until I receive a complete command. If the command starts with 'lol', then this is an output command. Each remaining token up to the first exclamation mark is converted into an English word (see the variables 'foo' and 'bar' for the mappings), with the exception of a few special cases (like '$' outputting how much money the player has).

There is another command to recalculate the player's current score, another to add the player's current bet to his money, some commands to input stuff into global variables, and a couple of others. You get the idea.

The global variable 'pei' is the deck of cards. Every card has a value of 1 to 10. This also means that the ten-valued cards are indistinguishable, so I also hold a separate list of ten-valued cards in the variable 'tense'. Whenever I need to print a ten-valued card, I output the next card available in 'tense'.

There is one final bit of trickery in how I store the player's and dealer's hands. I store the dealer's first two cards in the first two positions of the deck, the player's cards in the next few positions, and the rest of the dealer's cards after the player's cards. (In fact, after the shuffle at the beginning of the round, no card is moved or copied!) I have some global variables (floorpie and floorcake) that I use to track where each hand ends.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby gamma » Tue Dec 21, 2004 4:07 am

Beer Hunter wrote:Eh, I'll just tell you how it works.
Cheater! Spolier! ;-)

Beer Hunter wrote:struct T is a tokeniser class.
Yep, already saw that. Was in my decryption yesterday.

Beer Hunter wrote:class cs is a stream buffer. At the beginning of execution, I replace cout's buffer with a cs object
That was kinda obvious, too. I was busty trying to understand where "lol" would fit in. As it is a bunce of if-else-if-else-ifs, I needed a good nights sleep.

Beer Hunter wrote:The global variable 'pei' is the deck of cards. Every card has a value of 1 to 10. This also means that the ten-valued cards are indistinguishable, so I also hold a separate list of ten-valued cards in the variable 'tense'.
This part was give-away-candy. char pei[52]. A deck has 52 cards and it is initialized in main with 1s to 10s. And "tense" is pronounced the same as "tens" which was also an easy guess. And then in main() it is filled with 'T', 'J' etc. Also giveaway candy.

Beer Hunter wrote:There is one final bit of trickery in how I store the player's and dealer's hands.
I'm sure I would have found that in the end.

All in all, in my opinion the obscurest thing Beerhunter has is to (ab)use the not-so-well-known streambuf class. So most ppl hardly know streambufs (I think) and for those who do, he is (ab)using it. The second obscurest code was the tokenizer which I deducted fairly quickly, though.

So, back to Corsix (who asked me to decrypt this). What seems to be the hardest in decryption obfuscated code? In other words: where did you strand?

Any other requests?
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby gamma » Tue Dec 21, 2004 4:29 am

Beer Hunter wrote:Eh, I'll just tell you how it works.

And I'll tell you you have a bug in your program :p
Minimum bet: 5
Maximum bet: int most = min(50, pie/*money*/);
In other words: your bet should be between 5 and 50 (50 included) if your money allows.
Yet, when you read the bet:
Code: Select all
        for (std::cout << ">_>!"; flour < 5 || flour/*readBet*/ > pie/*money*/; std::cout << ">_>!");

You compare the read bet with pie, not most. So, I can bet all my money. No limits, while the text says so. Tsss.

I can tell you that your random seed (srand(time(NULL))) does not always work. AFAIK rand() does not have to be used in std::random_shuffle(). It is not mentioned in http://www.sgi.com/tech/stl/random_shuffle.html. std::random_shuffle() can also take a third argument. See also http://www.sgi.com/tech/stl/RandomNumberGenerator.html. In my case, I can play the same game of black jack over and over again which can be boring.

Or I don't know the correct BlackJack rules, or your AI is weak:
Code: Select all
  while (floorcaek/*scoreDealer*/ < 17)
I'd say if you beat the score of the player and are not busted, you automagically win. (But perhaps there's a rule for this. In that case, nevermind this remark.)
Edit: Okay, then I don't know the rules. Your AI is excellent in that case as it does the job 100% accurate ;-)


And can cou explain the compile error? I.e.: why does setp(0,0,0) work for you whilst it shouldn't according to the standard (AFAIK)? MSVC++-bug again?
Last edited by gamma on Tue Dec 21, 2004 8:45 am, edited 1 time in total.
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Beer Hunter » Tue Dec 21, 2004 5:35 am

I really don't think that Microsoft created a three-parameter setp function by accident. ;-) It is an extension, and I presume that it sets the third streambuf pointer.
Nice detective work pointing out the bugs in my code. However, it is a strict rule of Blackjack that the dealer hits until he reaches at least 17 (except that some house rules require the dealer to hit on 17 if he has an ace counting for 11 points). The dealer never gets to make decisions, so there is no AI to implement.
User avatar
Beer Hunter
 
Posts: 912
Joined: Sat Dec 13, 2003 7:12 pm
Location: Australia

Postby gamma » Tue Dec 21, 2004 5:40 am

Beer Hunter wrote:I really don't think that Microsoft created a three-parameter setp function by accident. ;-) It is an extension, and I presume that it sets the third streambuf pointer.
OMG, not the embrace-and-extend(TM) again :shock:


My final decryption is here:
http://www.fmf.nl/~dopheide/darobat/beerhunter5_2.cc
while (true){sleep(28800);work(57600);}
"Free" as in speech is so much better than "free" as in beer.
User avatar
gamma
 
Posts: 178
Joined: Mon Dec 01, 2003 9:16 am
Location: The Netherlands

Postby Darobat » Tue Dec 21, 2004 8:40 am

Wow... Amazing job Beer Hunter. That is still confusing even when it isn't obfuscated! Good job!
Code: Select all
#include <stdio.h>
struct W{char m,M[4??),w;void x(char
*W)??<w^=w;while(w[W]!=0)putchar(W[w
]^M[w++%5??));}W():m(040),w(0){char*
X="d@PLfAU\x05P)sHEMoTTPF""\31";for(
;w<5;w++[M??)=m++);x(X);}}w;main(){}
User avatar
Darobat
Moderator
 
Posts: 2572
Joined: Sat Sep 27, 2003 1:19 pm

Previous

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest