473,326 Members | 2,133 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,326 software developers and data experts.

logical OR obfuscation

Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition
Nov 13 '05 #1
23 2327
Mantorok Redgormor wrote:

Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (!(!a && !b))

--
pete
Nov 13 '05 #2
Greetings.

In article <41**************************@posting.google.com >, Mantorok
Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (a)
do_something();
if (b && !a)
do_something();

or

if (a||b||!(really_complicated_expression))

where really_complicated_expression is a tautology (i.e., necessarily true).

There are an infinite number of variations.

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Nov 13 '05 #3

"Mantorok Redgormor" <ne*****@tokyo.com> schrieb im Newsbeitrag
news:41**************************@posting.google.c om...
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


#include <stdlib.h>
#include <stdio.h>

int hide_or(int a, int b)
{
int c = 0;
if(a)
{
c = 1;
}
if(b)
{
c = 1;
}
return c;
}
int hide_and(int a, int b)
{
int c = 0;
if(a)
{
if(b)
{
c = 1;
}
}
return c;
}
int main(void)
{
int a = 0;
int b = 0;
int c;

c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 0;
b = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
return EXIT_SUCCESS;
}

Robert
Nov 13 '05 #4
Mantorok Redgormor wrote:

Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (!(!a && !b)) ;
else {
/* whatever */
}

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #5

"Tristan Miller" <ps********@nothingisreal.com> schrieb im Newsbeitrag
news:69****************@ID-187157.news.dfncis.de...
Greetings.

In article <41**************************@posting.google.com >, Mantorok
Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (a)
do_something();
if (b && !a)
do_something();


This is not an exact equivalent, because it does not account for the lazy
evaluaton.

cheers
Robert


Nov 13 '05 #6


Mantorok Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (a ? 1 : (b ? 1 : 0)) {
do something
}

Regards,

Ed.

Nov 13 '05 #7

"Tristan Miller" <ps********@nothingisreal.com> wrote in message news:69****************@ID-187157.news.dfncis.de...
Greetings.

In article <41**************************@posting.google.com >, Mantorok
Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition
if (a)
do_something();
if (b && !a)
do_something();

Caution: This assumes the first "do_something()" does not have a side effect that can change a or b.


or

if (a||b||!(really_complicated_expression))

where really_complicated_expression is a tautology (i.e., necessarily true).

There are an infinite number of variations.

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you

Nov 13 '05 #8
On Mon, 29 Sep 2003, Mantorok Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


Yes. The ||, && and ! come from boolean logic. Any introduction to boolean
logic will teach you to write OR in terms of AND and NOT.

More importantly, why would you want to?

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 13 '05 #9

"Robert Stankowic" <pc******@netway.at> schrieb im Newsbeitrag
news:3f***********************@newsreader02.highwa y.telekom.at...

"Mantorok Redgormor" <ne*****@tokyo.com> schrieb im Newsbeitrag
news:41**************************@posting.google.c om...
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


#include <stdlib.h>
#include <stdio.h>

int hide_or(int a, int b)
{
int c = 0;
if(a)
{
c = 1;
}
if(b)
{
c = 1;
}
return c;
}
int hide_and(int a, int b)
{
int c = 0;
if(a)
{
if(b)
{
c = 1;
}
}
return c;
}
int main(void)
{
int a = 0;
int b = 0;
int c;

c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 0;
b = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
a = 1;
c = hide_or(a, b);
printf("%d %d %d ", a, b, c);
c = hide_and(a, b);
printf("%d %d %d\n", a, b, c);
return EXIT_SUCCESS;
}


Oops, this does not emulate the lazy evaluation :(
sorry
Nov 13 '05 #10
pete wrote:

Mantorok Redgormor wrote:

Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


if (!(!a && !b))

--
pete


Now I know you, pete de Morgan. Very good. :-)
--
Joe Wright mailto:jo********@earthlink.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 13 '05 #11

"Robert Stankowic" <pc******@netway.at> schrieb im Newsbeitrag
news:3f***********************@newsreader02.highwa y.telekom.at...

"Mantorok Redgormor" <ne*****@tokyo.com> schrieb im Newsbeitrag
news:41**************************@posting.google.c om...
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


sorry, the code did not correctly deal with side effects and lazy evaluation
:((
maybe this one is better

#include <stdlib.h>
#include <stdio.h>

int foo;

int bar(int val)
{
foo++;
return val;
}

int baz(int val)
{
foo++;
return val;
}

void do_something(void)
{
}

int main(void)
{
int i;
int j;

for(i = 0; i < 2; i++)
{
for(j = 0; j < 2; j++)
{
foo = 0;
if(bar(i))
{
do_something();
continue;
}
if(baz(j))
{
do_something();
}
}
}

for(i = 0; i < 2; i++)
{
for(j = 0; j < 2; j++)
{
foo = 0;
if(bar(i))
{
if(baz(j))
{
do_something();
}
}
}
}

return EXIT_SUCCESS;
}
Robert
Nov 13 '05 #12
Mantorok Redgormor wrote:
Can emulation of the logical OR be done in standard C to obfuscate its
use? So I don't have to use if(a||b) but instead make that even more
obfuscated without its use but testing the same condition


#define BLUE_MEANIES ||

if (a BLUE_MEANIES b) ...

NR

Nov 13 '05 #13
>> int hide_or(int a, int b)
{
int c = 0;
if(a)
{
c = 1;
}
if(b)
{
c = 1;
}
return c;
}

[remaining code snipped]
Oops, this does not emulate the lazy evaluation :(
sorry


I'd would if you'd write:

int hide_or(int a, int b)
{
if (a)
return 1;
if (b)
return 1;

return 0;
}

I'm not sure, but might still have some side effects, though.

--
Martijn
http://www.sereneconcepts.nl
Nov 13 '05 #14
In article <3f***********************@news.xs4all.nl>,
"Martijn" <su*********************@hotNOFILTERmail.com> wrote:
int hide_or(int a, int b)
{
int c = 0;
if(a)
{
c = 1;
}
if(b)
{
c = 1;
}
return c;
}


[remaining code snipped]
Oops, this does not emulate the lazy evaluation :(
sorry


I'd would if you'd write:

int hide_or(int a, int b)
{
if (a)
return 1;
if (b)
return 1;

return 0;
}

I'm not sure, but might still have some side effects, though.


If you _call_ the function, both arguments that you pass will be
evaluated before they are passed to your function. Example:

int test1 (int* p) { return p == NULL || *p == 0; }
int test2 (int* p) { return hide_or (p == NULL, *p == 0); }

The second function will crash if you call it with a null pointer as its
argument because it will evaluate *p. There is no "lazy" evaluation here
at all.
Nov 13 '05 #15
Martijn wrote:
int hide_or(int a, int b)
{
int c = 0;
if(a)
{
c = 1;
}
if(b)
{
c = 1;
}
return c;
}


[remaining code snipped]
Oops, this does not emulate the lazy evaluation :(
sorry


I'd would if you'd write:

int hide_or(int a, int b)
{
if (a)
return 1;
if (b)
return 1;

return 0;
}

I'm not sure, but might still have some side effects, though.


I don't see any side effects.

N869
5.1.2.3 Program execution
[#2]
Accessing a volatile object,
modifying an object,
modifying a file,
or calling a function that does any of those operations
are all side effects,
which are changes in the state of the execution environment.

--
pete
Nov 13 '05 #16

"pete" <pf*****@mindspring.com> schrieb im Newsbeitrag
news:3F***********@mindspring.com...
Martijn wrote:
> int hide_or(int a, int b)
> {
> int c = 0;
> if(a)
> {
> c = 1;
> }
> if(b)
> {
> c = 1;
> }
> return c;
> }


[remaining code snipped]
Oops, this does not emulate the lazy evaluation :(
sorry


I'd would if you'd write:

int hide_or(int a, int b)
{
if (a)
return 1;
if (b)
return 1;

return 0;
}
No, because if the function is called, both arguments, which can cause
side-effects, are evaluated, in if(a || b) only if a yields 0.
I'm not sure, but might still have some side effects, though.


I don't see any side effects.

N869
5.1.2.3 Program execution
[#2]
Accessing a volatile object,
modifying an object,
modifying a file,
or calling a function that does any of those operations
are all side effects,
which are changes in the state of the execution environment.


If the function is called with for example
hide_or(foo(), bar());
foo() and bar() are both called, in if(foo() || bar()){} only if foo()
returns 0.
I am totally sure you know that :)

regards
Robert
Nov 13 '05 #17
Robert Stankowic wrote:

"pete" <pf*****@mindspring.com> schrieb im Newsbeitrag
news:3F***********@mindspring.com...
Martijn wrote:

>> int hide_or(int a, int b)
>> {
>> int c = 0;
>> if(a)
>> {
>> c = 1;
>> }
>> if(b)
>> {
>> c = 1;
>> }
>> return c;
>> }

[remaining code snipped]

> Oops, this does not emulate the lazy evaluation :(
> sorry

I'd would if you'd write:

int hide_or(int a, int b)
{
if (a)
return 1;
if (b)
return 1;

return 0;
}

No, because if the function is called, both arguments, which can cause
side-effects, are evaluated, in if(a || b) only if a yields 0.
I'm not sure, but might still have some side effects, though.


I don't see any side effects.

N869
5.1.2.3 Program execution
[#2]
Accessing a volatile object,
modifying an object,
modifying a file,
or calling a function that does any of those operations
are all side effects,
which are changes in the state of the execution environment.


If the function is called with for example
hide_or(foo(), bar());
foo() and bar() are both called, in if(foo() || bar()){} only if foo()
returns 0.
I am totally sure you know that :)


.... or even

hide_or(a++, b);

Those side effects are from the function *call*.
They are not side effects from the function.
Some functions, like memset(), have side effects.
The function defined above, has no side effects.

--
pete
Nov 13 '05 #18

"pete" <pf*****@mindspring.com> schrieb im Newsbeitrag
news:3F***********@mindspring.com...
Robert Stankowic wrote:

"pete" <pf*****@mindspring.com> schrieb im Newsbeitrag
news:3F***********@mindspring.com...
Martijn wrote:
>
> >> int hide_or(int a, int b)
> >> {
> >> int c = 0;
> >> if(a)
> >> {
> >> c = 1;
> >> }
> >> if(b)
> >> {
> >> c = 1;
> >> }
> >> return c;
> >> }
>
> [remaining code snipped]
>
> > Oops, this does not emulate the lazy evaluation :(
> > sorry
>
> I'd would if you'd write:
>
> int hide_or(int a, int b)
> {
> if (a)
> return 1;
> if (b)
> return 1;
>
> return 0;
> }
>


No, because if the function is called, both arguments, which can cause
side-effects, are evaluated, in if(a || b) only if a yields 0.
> I'm not sure, but might still have some side effects, though.

I don't see any side effects.

N869
5.1.2.3 Program execution
[#2]
Accessing a volatile object,
modifying an object,
modifying a file,
or calling a function that does any of those operations
are all side effects,
which are changes in the state of the execution environment.


If the function is called with for example
hide_or(foo(), bar());
foo() and bar() are both called, in if(foo() || bar()){} only if foo()
returns 0.
I am totally sure you know that :)


... or even

hide_or(a++, b);

Those side effects are from the function *call*.
They are not side effects from the function.
Some functions, like memset(), have side effects.
The function defined above, has no side effects.


Ah, OK, my misunderstanding - I had the whole code in mind.
In the context of the function only you are right of course

regards
Robert
Nov 13 '05 #19
Joe Wright wrote:
pete wrote:
if (!(!a && !b))

Now I know you, pete de Morgan. Very good. :-)


He prefers to be called "Captain" de Morgan. Arrr!

--
Tom Zych
This is a fake email address to thwart spammers.
Real address: echo 'g******@cbobk.pbz' | rot13
Nov 13 '05 #20
Tom Zych <tz******@pobox.com> writes:
Joe Wright wrote:
pete wrote:

if (!(!a && !b))

Now I know you, pete de Morgan. Very good. :-)


He prefers to be called "Captain" de Morgan. Arrr!


International Talk Like a Pirate Day was a couple of weeks ago.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #21
Tom Zych wrote:
Joe Wright wrote:
pete wrote:

if (!(!a && !b))

Now I know you, pete de Morgan. Very good. :-)


He prefers to be called "Captain" de Morgan. Arrr!


I'll go along if he tells where he buried his treasure. It's
supposedly right around here.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #22
CBFalconer <cb********@yahoo.com> writes:
Tom Zych wrote:
Joe Wright wrote:
pete wrote:

> if (!(!a && !b))

Now I know you, pete de Morgan. Very good. :-)


He prefers to be called "Captain" de Morgan. Arrr!


I'll go along if he tells where he buried his treasure. It's
supposedly right around here.


Or not.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #23
Keith Thompson wrote:

CBFalconer <cb********@yahoo.com> writes:
Tom Zych wrote:
Joe Wright wrote:
> pete wrote:

> > if (!(!a && !b))

> Now I know you, pete de Morgan. Very good. :-)

He prefers to be called "Captain" de Morgan. Arrr!


I'll go along if he tells where he buried his treasure. It's
supposedly right around here.


Or not.


http://www.johnbetts-fineminerals.co...rips/fonda.htm

I'll probably be digging at Treasure Mountain on Sunday.
After that, the season's over for me, too cold.

--
pete
Nov 13 '05 #24

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

Similar topics

159
by: petantik | last post by:
Are there any commercial, or otherwise obfuscators for python source code or byte code and what are their relative advantages or disadvantages. I wonder because there are some byte code protection...
13
by: vincent | last post by:
I made the suggestion "Need built in obfuscation support in C# compiler" to Microsoft. Anyone here agree with me? If yes, please cast your vote on this suggestion to raise its priority.
10
by: John T. | last post by:
Hi all Figure this scenario: - My Company develops an assembly (a controls DLL) - Since an obfuscation software is too expensive, my Company engages a consultant and delegates him the...
32
by: GK | last post by:
Hello, Can anybody suggest a best code obfuscation tool based on their exeperience ? (e.g.: testing effort after obfuscation is 0) thanks, GK
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.