LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   C programming puzzle (http://www.linuxquestions.org/questions/general-10/c-programming-puzzle-770300/)

smeezekitty 11-19-2009 04:53 PM

C programming puzzle
 
Coolin' down from all the flame wars about making good code, its time to test how somone is at decoing bad code:
can you tell what this does without running it:
Code:

#include <conio.h>
#define DZF92(c, x) (((c)==0)?0:(((x%2)==0)?(c-1):(c-2)))
void pstx(char *s){
int i = 0;
while(putch(DZF92(s[i], (++i)))){
if(DZF92(s[i], i) == ','){gotoxy(wherex() + 1, wherey());}
}
}
int main(){
char boopalot[] = {' ', 74, 102, 110, 109, 113, 45, 121, 112, 116, 109, 102, 34, 0};
pstx(boopalot);
return 0;
}


mjones490 11-19-2009 05:18 PM

Looks to me like it prints "Hello, world!" on the screen.

smeezekitty 11-19-2009 07:58 PM

Quote:

Originally Posted by mjones490 (Post 3763184)
Looks to me like it prints "Hello, world!" on the screen.

LOL you must have ran it.

sarum1990 11-19-2009 08:15 PM

That's pretty cool, I actually went through it line by line. Awhile ago I stumbled across a single file that was, a bash program, a Makefile, and C source code, all with very tricky comment notation so that if you made the file executable, you could like run it 3 times and compile and run a C program. That was probably the craziest obfuscation I've seen in code. Can't find it now, but it was really interesting.

mjones490 11-20-2009 09:05 AM

Quote:

Originally Posted by smeezekitty (Post 3763298)
LOL you must have ran it.

I ran it on my brain.

No, it's just that I've seen enough obfuscated "Hello, World!" programs to recognize the ASCII codes for the letters, and with the little "subtract one from every other character", that accounts for the simple mutations in the codes.

mjones490 11-20-2009 09:13 AM

My favorite obfuscated program is the one with three lines of mostly parentheses, that when you run it it prints out a naked woman showing her poonanners to the whole world.

smeezekitty 11-23-2009 02:23 AM

Quote:

Originally Posted by mjones490 (Post 3763901)
My favorite obfuscated program is the one with three lines of mostly parentheses, that when you run it it prints out a naked woman showing her poonanners to the whole world.

obfuscation is fun!


All times are GMT -5. The time now is 06:44 PM.