wu :: forums
wu :: forums - Obfuscated code

Welcome, Guest. Please Login or Register.
Sep 23rd, 2018, 8:25pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Icarus, ThudnBlunder, william wu, SMQ, Grimbal, towr, Eigenray)
   Obfuscated code
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Obfuscated code  (Read 19212 times)
-D-
Guest

Email

Obfuscated code  
« on: Aug 6th, 2002, 11:35am »
Quote Quote Modify Modify Remove Remove

The code isn't so obfuscated when it's written like PROPER code....
 
#include <stdio.h>
#define _ F-->00 || F-OO--;
void F_OO();
long F=00,OO=00;
void main()
{
 F_OO();
 printf("%1.3f\n", 4.0*-F/OO/OO);
}
void F_OO()
{
...
}
 
This is pretty much the first 3 lines expanded.
 
The #define is a macro that defines the _ character.  But it is only expanded for cases where the _ isn't used in a label (such as it is used in F_OO ).  
 
F_OO is actually a function that uses long drawn out operation on F and OO to make them become -202 and -16 respectively.  
 
4 * -202 / -16 / -16 = 3.156 which is what is printed out.  The 4. in the given code is really 4.0.  the - sign is actually a unary minus making the -202 into 202, it doesn't do a subtraction.  It wouldn't have been as obfuscated if it had been written -4.*F/OO/OO see?  
 
So, the code calls the F_00 function to change the values of F and OO, then prints out some math mangling of those values.
 
The last thing that makes this code more complicated is that they didn't declare their return types for F_OO or main and attempted to assume then as void (which is invalid, proper C would default them to integers).  I'll ignore errors associated with not declaring includes or function prototypes and assume those were just not put in the excerpt.
-D-
 
IP Logged
anton
Guest

Email

Re: Obfuscated code  
« Reply #1 on: Dec 25th, 2004, 12:28am »
Quote Quote Modify Modify Remove Remove

Since 4.*-F/OO/OO results in an approximation of Pi, we get:
Pi = -4F/OO2
Pi*(OO/2)2 = -F
 
It makes sense to assume that OO is the diameter of a circle, and F is its area (negative). The circle is actually the one "drawn" in the function F_OO(). Later, I will replace F with a and OO with d.
 
Let's see what happens in the F_OO function. Each line consists of "_" followed by a string of "-_". Each "_" is replaced with "a-->0 || a-d--;" which means following:
  • Subtract one from a. (a--)
  • If, before the subtraction, a was negative then perform "a-d--", since the operator || executes its right part only when the left part is false. The meaningful action here is only "d--"; that is, subtract one from d.

The underscore in each "-_" is replaced with the same thing; the only difference is the initial minus sign. Now -a is compared with zero; since -a is always positive, the second part never gets executed.
 
And now we get the full picture: each of "_" and "-_" decreases a by one; thus, a contains the negative area of the circle. In addition, each initial "_" decreases d by one - in the end d becomes equal to the negative height of the circle, which is the same as its diameter.
IP Logged
Paul
Newbie
*





   


Posts: 1
Re: Obfuscated code  
« Reply #2 on: Apr 6th, 2013, 10:07pm »
Quote Quote Modify Modify

People keep showing fractions of pi.You all need to realise pi is a whole number and the rest of the numbers are the fractions.Point then nonpoint.The nonpoint should be a whole number?Ok,seems right doesn't it?
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright 2000-2004 Yet another Bulletin Board