views:

262

answers:

2

Hey all, I'm looking for ways to obfuscate the following c#/silverlight source code:

    if (searchBox.Text.Equals("string literal")){
        MessageBox.Show("another string literal");
    }

So far all I can come up with to hide it is encoding the strings as arrays of ascii...

Thanks

EDIT All I want is for the source code to be undreadable, this is for an easter egg. Security is not a priority for me. Thanks.

EDIT 2 I don't want the presence of an easter egg to be known. I'm trying to obfuscate the program flow so it doesn't appear like there is a line of code like

if (specialcase)
    doEasterEgg();

I've seen stuff on like the obfuscated c contest where hello world turns into globbidy gook. Anyhing similar that people know of for c#?

+2  A: 

What exactly do you want to protect against?

  • The transmission of the text value of the control to your server? In that case, any "obfuscation" by any non-encryption technique will easily be overcome by a motivated attacker. You should look into encrypting your strings, rather than obfuscating them.

  • If you're looking to obfuscate your source code itself, you really should let a third party tool handle it. Anything you might invent on your own is likely to be easily reverse-invented.

  • EDIT: If you just want to hide an Easter Egg, how about using ROT13?

  • EDIT 2: How about assigning them misleading constants and referencing them in a different static class that is misleadingly named?

.

// in other source file ValidateInput.cs
public const VALID_STRING = "secret";

public class ValidateInput {
    public static bool Validate(string srcText)
    {
         return srcText == VALID_STRING;
    }
    public static void LogicValidSearch()
    {
         return;
    } 
}

//In your main application
if (ValidateInput.Validate(searchBox.Text)) {
    ValidateInput.LogValidSearch();
}
Mike Atlas
Well I know a bunch of ways to encrypt the string literal, I took a cryptology course. But I don't want anyone to even know there IS an easter egg. So I can't have a line of code that looks like If special case: do easter eggIs there anyway to obfuscate that program flow? For example, something like writing a function and somehow putting it in a dll or anything? I don't actually know what that means but I've heard it tossed around. Thanks
JGord
See my new edit...
Mike Atlas
Ah yes, that's more what I was looking for... best answer so far!
JGord
Just a little creative naming to throw them off ;)
Mike Atlas
+1  A: 

There's not enough code here to obfuscate effectively. Your only option is hashing the value of "string literal" and encrypting the value of "another string literal". This technique is not safe either because you would have to expose your encryption method.

BC