# Thread: Obfuscated Code Contest: The Results

1. Hello,

It's quite simple indeed. For instance:
Code:
```int main() {
int bc;

bc = 84;

return 0;
}```
Could be obfuscated as the following:
Code:
```#define a int
#define d 0x54
a main() {a bc=(a)d;return d-d;}```
In this example, a represents and integer. d is a hex value which represents the number 84. We create an integer called bc which equals the type cast of 0x54 which is 84. Lastly, main returns 0, as [84-84 = 0]. That is a sample obfuscated code example.

- Stack Overflow

2. I just started messing around, and it doesn't work:
Code:
```#define hello int
#define abc int=20*4-7/3*8/.333-504-.584584584584584584584584584585
#define st if
#define abb int=80*4-300*40/5-300-20
#define haha (
#define laugh cout<<

hello main() {st haha abc==abb);laugh"hello world";}```
I just guessed on what to do. So what all rules apply?
It says syntax error before '=' token. 'cout' undeclared first use this function. In function main 'int main()'.
Edit: Can you define stuff with more than one letter?

3. Code:
`abc==abb`
Code:
`int=20*4-7/3*8/.333-504-.584584584584584584584584584585==int=80*4-300*40/5-300-20`
And the use of int there is invalid.

When using macros, never forget that they're just dumb text replacement.

4. I made those numbers myself they should both equal 80. So what should I do just put the math where the ints are? Why can't I use the ints right there?

5. You can. Just remove the int= from the macro expansions.

6. Alright fixed that. So what do I do about in function 'int main()' and cout undeclared(first use this function)?

7. You still need to include <iostream>, and let laugh expand to std::cout<<.

BTW, you shouldn't write obfuscated code that way. The way to write obfuscated code is to first write working normal code. Then you take parts out and replace them by macros. This way you'll know that the program works.

8. Sorry, I don't know what macros are.
My fixed code:
Code:
```#include <iostream>
#define hello int
#define abc 20*4-7/3*8/.333-504-.584584584584584584584584584585
#define st if
#define abb 80*4-300*40/5-300-20
#define haha (
#define laugh std::cout<<
#define bye std::cin.get()
#define byeo std::cin.ignore()

hello main() {st haha abc==abb);laugh"hello world";
byeo;
bye;
}```

I look at Jessycat's code and it has stuff like he1lo, but in the .c code it is stuff like us2. Why is that?

9. #define macro_name macro_expansion

I hope that explains

10. Just look at jessycat's code how can you make a hello world program without "hellworld in there somwhere?

11. Originally Posted by cerin
I look at Jessycat's code and it has stuff like he1lo, but in the .c code it is stuff like us2. Why is that?
When I wrote the first version (the normal, readable version) I was putting alot of numbers in for the ASCII art. Instead of typing 32,32,32,32 to represent the ASCII values of 4 spaces, I defined a macro called sp4 so that when i needed 4 spaces I would just have to type sp4, and when the compiler got ahold of my code it would replace every instance of sp4 with the literal values 32,32,32,32. Additionally, when I was looking back over the values, I could see that I had put sp4 and if I had actually wanted 4 underscores, I could easily change it to us4 instead of deleting and replacing a bunch of literal values. In that case, the #defines were being used as a way to make it more easily readable to a human being (the computer doesn't care either way).

Once my code was complete and worked the way I wanted it to, I then went about replacing EVERYTHING with variations of "hello" and "world". Since the compiler will treat foo, foO, fOo, fOO, Foo, FoO, FOo and FOO as 8 different variables, I just did the same thing. Because I thought I might run out of variations of hello world, I also used 1's (ones) for L's and 0's (zeros) for o's and then kind of randomly defined one of these variations to something in the program. So, for anything that needed to literally be replaced I used a #define to make the compiler replace text, and any variable or function name that I had made up I just changed it, for example from TRANSLATE to WORLD and no replacement by the compiler is necessary since it was a user defined variable to begin with. In this case, the #defines were used to make the code extremely difficult to read (in other words, obfuscate the code!).

Once the compiler gets ahold of my neat ASCII art, it will literally replace most of it with variable and function names (and various symbols) that make sense to a 'C' compiler. Then it will go through the processed code and compile it just like any other program, looking to make sure syntax is correct, make sure variables are used appropriately, etc. and finally generate machine instructions so that the program can be executed by the computer it was compiled for.

Originally Posted by cerin
Just look at jessycat's code how can you make a hello world program without "hellworld in there somwhere?
If you look at the "readable" code I included and follow it, you'll find that if the user did not type any command line arguments the main() function mallocs space for 12 characters in a char* array and then assigns the characters "H E L L O , W O R L D !" to it. Next, it sends that char*array to the other functions which go about translating those characters to the appropriate ASCII art representations and then displaying the ASCII art.

Does that help?

12. Originally Posted by cerin
how can you make a hello world program without "hellworld in there somwhere?
The same way I did:
Code:
```#include <stdio.h>
#define _1(x) putchar((l)=(x));
#define _2(x) ((l)<<(x))
#define _3(x) ((l)>>(x))
#define _4(x,y) ((x)&(1<<(y)))
#define _5(x) ((unsigned char)(~(x)))
#define _6(x,y) ((x)&(y))
#define _7(x,y) ((x)>>(y))
#define _8(x,y) ((x)<<(y))
#define _9(x) ((l)+(x))
#define _10(x) return (x);
int main(void){unsigned char l=1;_1(_2(6)+8)_1(_4(_2(1),7)-_4(127,4)-11)_1(_9(_4(l,2)+_4(l,2)-1))_1(_5(_5(l)))_1(_9(_6(_5(l),3)))_1(_4(l,5))_1(_2(2)-_3(2)-1)_1(l-_4(_2(1),3))_1(_9(_6(l,3)))_1(l-_3(4)+1)_1(l-(_8(_7(l,_3(4)),3)))_1(_8(_7(l,6),5)+1)_1(_2(3)+2)_10(_2(5))}```

13. Stack Overflow
That Is Inceridble how much free time you have!

14. Heh,

Thanks. I didn't expect the Off-Site library to take nearly 3 weeks to assemble, nor 11 running contestants. Though, I wanted it perfect. So I overhauled the design two or three times. Each submission was built and tested on multiple platforms. I was lucky to finish on time. It was fun though. Especially gathering all the build logs and execution output for each submission per compiler and platform.

Best of all, it turned out to be a success.

- Stack Overflow

15. Originally Posted by Stack Overflow
Best of all, it turned out to be a success.
I think the Off-Site library you made was wonderful. It took only a few clicks to determine how it was laid out, and the colors and layout are not only easy on the eyes but are also attractive. Thank you for putting your time and effort into it. You made it easy for me to look over the other contestants' entries.