views:

335

answers:

8

Rules are simple. Write an obfuscated function in any language that takes in an integer and returns the same integer. Try to use math tricks and not language tricks. IE. Try to make your function portable.

+7  A: 

I chose English.

  1. Ask someone to tell me a number between 1 and 100.
  2. Locate a stranger and ask stranger to guess a number between 1 and 100.
  3. If the guess is not the same as the original number, go to step 2.

Chances are people will not only fail to figure out what I'm trying to accomplish, but they'll even question whether I myself know what I'm doing. Top that. :)

280Z28
Do you need a step 4: Return matched number?
Jon Smock
[I claim] It has special semantics, so no. :)
280Z28
+3  A: 
public int dsaiufgbysaukldf(int UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf)
{
   int UYigvuygBUYgb78btI76Rcr651VUytrOVBGUvuftgdsf= 3;
   int UYigvuygBUYgb78btl76Rcr651VUytr0VBGUvuftgdsf= 12; 
   UYigvuygBUYgb78btl76Rcr651VUytr0VBGUvuftgdsf = UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf* UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf% UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf;
   return UYigvuygBUYgb78btI76Rcr651VUytr0VBGUvuftgdsf;
}

I could do better, but you got the idea...

Samuel Carrijo
The irony here is that if you ran it through a code obsfucator, it would probably shorten the variable names and make it easier to see what it does.
Daniel Earwicker
That's sad. I liked this code
Samuel Carrijo
+2  A: 

C#

static int Identity(int val)
{
    if (val != 3547247 && val != 8224772)
        return val;
    return new Random(val).Next(0, 10000000);
}
John Rasch
what if your random value came up as 3547247 or 8224772?
Jason w
@Jason - That's exactly what it does otherwise it wouldn't be an identity function - the obfuscation here is that you can't possibly know that unless you tested the `Random.Next()` call yourself
John Rasch
+1  A: 
int euler(int x) {
    return -x*pow(e, i*pi)
}
Pyrolistical
+4  A: 
def mystery_converter(x):
    ''' BEWARE THE POWER! '''
    secret_sauce = int('0x7cb',16)
    mysterious_1 = sum(ord(s) for s in "Jon Skeet")
    mysterious_2 = sum(ord(s) for s in "Chuck Norris")
    return x + secret_sauce - (mysterious_1 | mysterious_2)
Anon
+5  A: 
def f(i):
    d = lambda x: [(n, max(e for e in xrange(len(bin(x)) - 2) if not x % n ** e))
                   for n in xrange(2, x / 2 + 1)
                   if not x % n and d(n) == [(n, 1)]] or [(x, 1)]
    return reduce(lambda x, y: x * y[0] ** y[1], d(abs(i)), i and i / abs(i))

Who's the first to explain what happens here?

Edit: Okay, here's the rundown.

The function d(x) conducts a prime factorization of the number x. It does so by finding all numbers from 2 to x/2 that divide x. If there's none, x is prime, and d(x) returns [(x,1)], i.e. x1.

All found divisors n are checked for primarity (by recursively calling d(n)). If n is prime, the maximal exponent e such that ne divides x is searched for.

An upper bound for e is floor(log2(x)), which happens to be one less than the length of the binary representation of x, hence the "len(bin(x)) - 2" part (the function bin() prepends "0b").

(n, e) is then part of the result list, meaning ne.

The main part of f(i) uses d to get the prime factorization of abs(i), and then uses reduce to multiply the resulting prime powers, starting with an initial value of "i and i / abs(i)", which means -1, 0, or 1 depending on the sign of i.

The extra handling of non-positive numbers is not strictly necessary, because d(-24) == [(-24, 1)] would do the right thing. But then again, that's boring, because we'd more or less just be passing around the value of i. Also, who's looking for neccessity in this question?

balpha
Madness. That's what happens.
Kitsune
Prime factorization.
starblue
@starblue: Well, finally! Almost 19 1/2 hours :-) I gave you a "Nice Answer" badge for that.
balpha
A: 
static string GetOriginalNumber(string inputNumber)
{
    inputNumber.Replace("1","2").Trim().Concat("A man a pan a panama").Replace("A man","panama").Replace("panama","42");
    //By the magic of constant strings, I give you the original number!
    return inputNumber;
}

I know, not terribly creative. shrug.

GWLlosa
A: 
private object StackOverFlow1195337(int a)
{
    int r;
    int z;
    int p;
    int t;
    int x;
    const int c = 4;
    const int d = 2;

    r = a;
    z = (a + c);
    r += 1 + ((a + c) + (a + d));
    p = (a + d);
    t = z + p;
    x += t - p + (r + a) - (a + a + a);
    r = ((a + t + 1) / (r - ((z + p) - t))) * (a * (0.5 + (2 * 0.25) + (x * (x - x))));
    return r;
}
Darknight