473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Obfuscate C tricks

I have been looking at the winning entries for the International Obfuscated
C Contest (Shame I missed it till it had closed, well next time I will get
an entry in) and I was wondering if anyone has any good suggestions for
tricks that can be used to Obfuscate C code. *

Some trick that I like to use include the following.

a^=a;
instead of
a=0;

5[b];
instead of
b[5];

and of course
a=(!(a^a))?1:0;
instead of
if (a) {
a=0;
} else {
a=1;
}

* Before people take great delight in flaming me for posting this I would
like to say that I am not actively stating that C should ever be coded like
this except when entering an Obfuscated competition.
--------------
Jason Cooper

Nov 14 '05 #1
11 3534
J.L.Cooper wrote:
I have been looking at the winning entries for the International Obfuscated
C Contest (Shame I missed it till it had closed, well next time I will get
an entry in) and I was wondering if anyone has any good suggestions for
tricks that can be used to Obfuscate C code. *

Some trick that I like to use include the following.

a^=a;
instead of
a=0;

5[b];
instead of
b[5];

and of course
a=(!(a^a))?1:0; Surely (a^a) is always 0 so a becomes 1 instead of
if (a) {
a=0;
} else {
a=1;
}

* Before people take great delight in flaming me for posting this I would
like to say that I am not actively stating that C should ever be coded like
this except when entering an Obfuscated competition.
--------------
Jason Cooper

Nov 14 '05 #2
Sorry should have been
a=(!(a^b))?1:0;
instead of
if (a==b) {
a=0;
} else {
a=1;
}
--------------
Jason Cooper
a=(!(a^a))?1:0;
instead of
if (a) {
a=0;
} else {
a=1;
}

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004

Nov 14 '05 #3


Sorry should have been
a=(!(a^b))?1:0;
instead of
if (a==b) {
a=0;
} else {
a=1;
}


That would do the same as a = (!(a^b)) ? 0 : 1; not a = (!(a^b)) ? 1 : 0;

Greetings, Chris.

Nov 14 '05 #4
J.L.Cooper wrote:

I have been looking at the winning entries for the International Obfuscated
C Contest (Shame I missed it till it had closed, well next time I will get
an entry in) and I was wondering if anyone has any good suggestions for
tricks that can be used to Obfuscate C code. *

Some trick that I like to use include the following.

a^=a;
instead of
a=0;


a = '-'-'-';

--
pete
Nov 14 '05 #5

There was an entry by David Korn in 1987 that used the fact that on most
(all?) Unix platforms you automatically have:

#define unix 1

even if you didn't include anything. I think he combined it with the
fact that a[i] = i[a] which resulted in something roughly in the form of

unix["unix"]

in order to yield 'n'.

Greetings, Chris

--
Christian Staudenmayer
University of Ulm, Germany
cs****@mathematik.uni-ulm.de
Nov 14 '05 #6
Opps. You are correct the one and zero should be swapped round.
--------------
Jason Cooper

"Christian Staudenmayer" <ch********************@mathematik.uni-ulm.de>
wrote in message news:20*********************@bovine.lan...


Sorry should have been
a=(!(a^b))?1:0;
instead of
if (a==b) {
a=0;
} else {
a=1;
}


That would do the same as a = (!(a^b)) ? 0 : 1; not a = (!(a^b)) ? 1 : 0;

Greetings, Chris.

Nov 14 '05 #7
"J.L.Cooper" <A@A.COM> wrote:
Sorry should have been
a=(!(a^b))?1:0;
instead of
if (a==b) {
a=0;
} else {
a=1;
}

Opps. You are correct the one and zero should be swapped round.


Both of these are more obfuscated than:
a = (a == b);

PS. When posting in comp.lang.c please write your comments
AFTER the ones you're replying to.
Nov 14 '05 #8
Old Wolf wrote:
a = (a == b);


a = a == b;

--
pete
Nov 14 '05 #9
J.L.Cooper wrote:
I have been looking at the winning entries for the International Obfuscated
C Contest (Shame I missed it till it had closed, well next time I will get
an entry in) and I was wondering if anyone has any good suggestions for
tricks that can be used to Obfuscate C code. *

Some trick that I like to use include the following.

a^=a;
instead of
a=0;

5[b];
instead of
b[5];

and of course
a=(!(a^a))?1:0;
instead of
if (a) {
a=0;
} else {
a=1;
}

Of course the preprocessor is fun as well.
#define ZAP(x) (x = 0)
#define EQ ==
#define NEQ !=
#define when if
#define end }
#define test
#define val_a a=
#define then {
#define unless(x) if(!x)

when(a)
ZAP(a);

if(x EQ 40) then
test val_a 20;
end

More fun is also to encode strings, and do hell of a job
decoding it.

#define a ;
#define a_o_ exit
#define _ 100
#define _n_ putchar
#define a_o(_l,l_)_l##l_
#define _a_(_l,l_)a_o(l_,_l)
#define ___ _n_(_-68)
int o__[_-93]={_-27,_+8,_+18,1+_,_+21,_+17,_-67} a int o=_-_ a
_a_(a_o(i,n),a_o(m,a))(__o,O,__){if(++__==_-26||__--==_+2)(___) a
if(__==_+8||__==_+((O=26)-5)) a_o((_n_(_+11)),a
if)((o)>7)a_o_(_n_(o+O-24))a _a_(a_o(i,n),a_o(m,a))
(__,O,_n_(a_o(o,__)[o++]))a}
Nov 14 '05 #10
"J.L.Cooper" <A@A.COM> wrote in message news:<cn**********@sun-cc204.lut.ac.uk>...
I have been looking at the winning entries for the International Obfuscated
C Contest (Shame I missed it till it had closed, well next time I will get
an entry in) and I was wondering if anyone has any good suggestions for
tricks that can be used to Obfuscate C code. *

<snip>

#include <stdio.h>

int main(void)
{
int a, b, c;
a = b = c = 0;

a = 42; /*
b = 43; * Perform calculation
c = 44; */

printf("a = %d, b = %d, c = %d\n",
a, b, c);

return 0;
}

$ gcc -O2 -Wall -ansi -pedantic -o tricky tricky.c
$ ./tricky
a = 42, b = 0, c = 0
Credit for this is due to the author of the "How to Write
Unmaintainable Code" document floating around.
Mark F. Haigh
mf*****@sbcglobal.net
Nov 14 '05 #11
In article <f8**************************@posting.google.com >,
Mark F. Haigh <mf*****@sbcglobal.net> wrote:
"J.L.Cooper" <A@A.COM> wrote in message news:<cn**********@sun-cc204.lut.ac.uk>...
I have been looking at the winning entries for the International
Obfuscated C Contest (Shame I missed it till it had closed, well next
time I will get an entry in) and I was wondering if anyone has any good
suggestions for tricks that can be used to Obfuscate C code. *
<snip>

#include <stdio.h>

int main(void)
{
int a, b, c;
a = b = c = 0;

a = 42; /*
b = 43; * Perform calculation
c = 44; */

printf("a = %d, b = %d, c = %d\n",
a, b, c);

return 0;
}

$ gcc -O2 -Wall -ansi -pedantic -o tricky tricky.c
$ ./tricky
a = 42, b = 0, c = 0


Oh, very nice. Very tricky, indeed!
Credit for this is due to the author of the "How to Write
Unmaintainable Code" document floating around.


Is that subtitled:
"And keep yourself employed: Job skills for programmers"
?

It sure works around here.

Nov 14 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mthlv12 | last post by:
I am using the latest version of eclipse to develop a java application. Is there an obfuscate button in eclipse ?
2
by: mthlv12 | last post by:
Does the eclipse ide have an obfuscate button ?
3
by: Aaron | last post by:
How would code obfuscation affect performance? in .net C#
11
by: RF | last post by:
Hi All, I need some help from experts of preparing an application for obfuscation and installation. A solution with two projects: 1. I have a standard windows form app with an implemented...
20
by: Drebin | last post by:
It's a long story really, but the bottom line is we need to encrypt or obfuscate a clear-text 9-digit SSN/taxpayer ID into something less than 21 characters. It doesn't need to be super-secure,...
20
by: twigster | last post by:
Hey everyone, I'm looking for a good way to obfuscate some Javascript code. Does anyone have a good experience or bad experience with a particular software? thanks
0
by: e.expelliarmus | last post by:
check this out buddies. kool website for: * hacking and anti hacking tricks * anti hackng tricks. * registry tweaks * orkut tricks * small virus * computer tricks and loads of different...
1
by: JosAH | last post by:
Greetings, Introduction This week's tip describes a few old tricks that are almost forgotten by most people around here. Sometimes there's no need for these tricks anymore because processors...
0
by: nelmr | last post by:
Hey guys, I've tried and tried to find a walk thru that works. Since I am using VS C# 2008 express, i am using clickonce deployment. I am targeting the 2.0 framework as I am not using any 3.5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.