473,809 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

un-obsfuscating -> into pascal an IOCCC obsfuscated program

Hi All,

I am attempting to reverse-obsfuscate an IOCCC entry, and my ultimate
goal is to convert the code into Delphi (OO Pascal).

I don't understand what the question-mark (?) operator, and the
percent (%) operator does.

How do I translate this line (obviously declaring some integers) into
pascal ???

int c = 0, *n = v + 100, j = d < u - 1 ? a : - 9000, w, z, i, g, q
= 3-f;

And how do I translate these lines to pascal ???

for(w = i = 0; i < 4; i++)
w += (m = v[h[i]]) == f ? 300 : m == q ? - 300: (t = v[ih[i]])
== f ? - 50: t == q ? 50 : 0;

And how do I translate these lines to pascal ???

for(; t < 1600; t += 100)
for(m = 0; m < 100; m++)
V[t + m] = m < 11 || m > 88 ||(m + 1) % 10 < 2 ? 3 : 0;

What does "<<" do ? e.g. how do I translate the next line???

return d >= u - 1 ? j + (c << 3): j;

Any help will be appreciated.

Regards,
Peter W. :-)))
Sandy Bay, Hobart, Tas, AU.
obsfuscated code ("lievaart2. c")
-----
#define D define
#D Y return
#D R for
#D e while
#D I printf
#D l int
#D W if
#D C y=v+111;H(x,v)* y++= *x
#D H(a,b)R(a=b+11; a<b+89;a++)
#D s(a)t=scanf("%d ",&a)
#D U Z I
#D Z I("123\
45678\n");H(x,V ){putchar(".XO"[*x]);W((x-V)%10==8){x+=2; I("%d\n",(x-V)/1
0-1);}}
l
V[1600],u,r[]={-1,-11,-10,-9,1,11,10,9},h[]={11,18,81,88}, ih[]={22,27,72
,77},
bz,lv=60,*x,*y, m,t;S(d,v,f,_,a ,b)l*v;{l
c=0,*n=v+100,j= d<u-1?a:-9000,w,z,i,g,q=
3-f;W(d>u){R(w=i= 0;i<4;i++)w+=(m =v[h[i]])==f?300:m==q?-300:(t=v[ih[i]])=
=f?-50:
t==q?50:0;Y w;}H(z,0){W(E(v ,z,f,100)){c++; w=
-S(d+1,n,q,0,-b,-j);W(w>j){g=bz= z;
j=w;W(w>=b||w>= 8003)Y w;}}}W(!c){g=0; W(_){H(x,v)c+=
*x==f?1:*x==3-f?-1:0;Y c>0?
8000+c:c-8000;}C;j= -S(d+1,n,q,1,-b,-j);}bz=g;Y
d>=u-1?j+(c<<3):j;}m ain(){R(;t<
1600;t+=100)R(m =0;m<100;m++)V[t+m]=m<11||m>88||(m +1)%10<2?3:0;I( "Level:"
);V[44]
=V[55]=1;V[45]=V[54]=2;s(u);e(lv>0) {Z
do{I("You:");s( m);}e(!E(V,m,2, 0)&&m!=99);
W(m!=99)lv--;W(lv<15&&u<10) u+=2;U("Wait\n" );I("Value:%d\n ",S(0,V,1,0 ,-90
00,9000
));I("move:
%d\n",(lv-=E(V,bz,1,0),bz ));}}E(v,z,f,o) l*v;{l*j,q=3-f,g=0,i,w,*k=v
+z;W(*k==0)R(i= 7;i>=0;i--){j=k+(w=r[i]);e(*j==q)j+=w; W(*j==f&&j-w!=k){W(
!g){g=1
;C;}e(j!=k)*((j-=w)+o)=f;}}Y g;}
-----

un-obsfuscated code:
-----
/* This source has been formatted by an unregistered SourceFormatX */
/* If you want to remove this info, please register this shareware */
/* Please visit http://www.textrush.com to get more information */

H(x,V)
{
putchar(".XO"[*x]);
if((x-V)%10==8)
{
x+=2;
printf("%d\n",( x-V)/10-1);
}
}

int V[1600], u, r[] =
{
- 1, - 11, - 10, - 9, 1, 11, 10, 9
}

, h[] =
{
11, 18, 81, 88
}

, ih[] =
{
22, 27, 72, 77
}

, bz, lv = 60, *x, *y, m, t;
S(d, v, f, _, a, b)int *v;
{
int c = 0, *n = v + 100, j = d < u - 1 ? a : - 9000, w, z, i, g, q
= 3-f;
if(d > u)
{
for(w = i = 0; i < 4; i++)
w += (m = v[h[i]]) == f ? 300 : m == q ? - 300: (t = v[ih[i]])
== f ? - 50: t == q ? 50 : 0;
return w;
}
H(z, 0)
{
if(E(v, z, f, 100))
{
c++;
w = - S(d + 1, n, q, 0, - b, - j);
if(w > j)
{
g = bz = z;
j = w;
if(w >= b || w >= 8003)return w;
}
}
}
if(!c)
{
g = 0;
if(_)
{
H(x, v)c += *x == f ? 1 : *x == 3-f ? - 1: 0;
return c > 0 ? 8000+c: c - 8000;
}
y=v+111;
H(x,v)*y++= *x;
j = - S(d + 1, n, q, 1, - b, - j);
}
bz = g;
return d >= u - 1 ? j + (c << 3): j;
}

main()
{
for(; t < 1600; t += 100)
for(m = 0; m < 100; m++)
V[t + m] = m < 11 || m > 88 ||(m + 1) % 10 < 2 ? 3 : 0;
printf("Level:" );
V[44] = V[55] = 1;
V[45] = V[54] = 2;
s(u);
while(lv > 0)
{
printf("123\456 78\n");
do
{
printf("You:");
s(m);
}
while(!E(V, m, 2, 0) && m != 99);
if(m != 99)lv--;
if(lv < 15 && u < 10)u += 2;
printf("123\456 78\n");
printf("Wait\n" );
printf("Value:% d\n", S(0, V, 1, 0, - 9000, 9000));
printf("move: %d\n", (lv -= E(V, bz, 1, 0), bz));
}
}

E(v, z, f, o)int *v;
{
int *j, q = 3-f, g = 0, i, w, *k = v + z;
if(*k == 0)
for(i = 7; i >= 0; i--)
{
j = k + (w = r[i]);
while(*j == q)j += w;
if(*j == f && j - w != k)
{
if(!g)
{
g = 1;
y=v+111;
H(x,v)*y++= *x;
}
while(j != k)*((j -= w) + o) = f;
}
}
return g;
}
-----

lievaart.hint
-----
Grand Prize:

Roemer B. Lievaart
VU Informatica
Churchilllaan 173-IV
Amsterdam, The Netherlands

We believe that you too will be amazed at just how much power Mr.
Lievaart packed into 1024 bytes!

This Plays the game of reversi (Othello)! Compile and run. It then
asks for a playing level. Enter 0-10 (easy-hard). It then asks for
your move. A move is a number within 11-88, or a 99 to pass. Illegal
moves (except for an illegal pass) are rejected. Then the computer
does its move (or a 0 to pass), until the board is full. It plays
rather well, for such a small program! Lievaart had to leave out the
board printing routine, so you'll have to take a real game board to
play it. ... Also due to space-limitations (the rules for 1987 had a
limit of 1024 byes), Lievaart took out the passing-handler, which
makes its ending-game rather poor. But further it knows all the
rules, uses alpha-beta pruning, and it plays f.i. on mobility(!).
Most important: it can play a pretty good game of Reversi!

The Author was kind enough to supply the fully functional version of the
program. The file lievaart2.c contains what the program would have
been without the size restriction. This version has the full end game
logic and displays the board after each move!

Copyright (c) 1987, Landon Curt Noll & Larry Bassel.
All Rights Reserved. Permission for personal, educational or
non-profit use is granted provided this this copyright and notice are
included in its entirety and remains unaltered. All other uses must
receive prior permission in writing from both Landon Curt Noll and
Larry Bassel.
-----
Nov 14 '05 #1
14 1799
On Sun, 06 Mar 2005 07:12:35 GMT, in comp.lang.c , "Peter Williams"
<pe*@bigpond.ne t.au> wrote:
Hi All,

I am attempting to reverse-obsfuscate an IOCCC entry, and my ultimate
goal is to convert the code into Delphi (OO Pascal).

I don't understand what the question-mark (?) operator,
?...: is more or less equivalent to if.. else...
and the percent (%) operator does.
remainder operator. 6%4 = 2
How do I translate this line (obviously declaring some integers) into
pascal ???

int c = 0, *n = v + 100, j = d < u - 1 ? a : - 9000, w, z, i, g, q = 3-f;
this declares a bunch of ints and one pointer to an int.
What does "<<" do ? e.g. how do I translate the next line???


bit left-shift operator. 0x01 << 4 = 0x10
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Nov 14 '05 #2
Peter Williams wrote:

I am attempting to reverse-obsfuscate an IOCCC entry, and my
ultimate goal is to convert the code into Delphi (OO Pascal).

I don't understand what the question-mark (?) operator, and the
percent (%) operator does.

How do I translate this line (obviously declaring some integers)
into pascal ???

int c = 0, *n = v + 100, j = d < u - 1 ? a : - 9000, w, z,
i, g, q = 3-f;


VAR
c, j, w, z, i, q : integer;
n : ^integer;

c := 0;
n := v + 100; (* Very questionable operation,
Pascal doesn't bandy pointers about *)
IF d < u-l THEN j := a
ELSE j := -9000;
q := 3 - f;

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #3
Peter Williams wrote:
Hi All,

I am attempting to reverse-obsfuscate an IOCCC entry, and my ultimate goal is to convert the code into Delphi (OO Pascal).


What's that 'Delphi (OO Pascal)'?
P.Krumins

Nov 14 '05 #4
"Peteris Krumins" <pe************ *@gmail.com> writes:
Peter Williams wrote:
Hi All,

I am attempting to reverse-obsfuscate an IOCCC entry, and my

ultimate
goal is to convert the code into Delphi (OO Pascal).


What's that 'Delphi (OO Pascal)'?


This is comp.lang.c, so we can't give you a good answer to that
question. I note, however, that there are at least 10 newsgroups
concerned with Delphi and that a Google search for "Delphi" will give
you more and better information than you could possibly get here.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
Hi All,

I can't quite figure out how to convert this line:

while(j != k)*((j -= w) + o) = f;

into pascal. Can someone please help?

Regards,
Peter W. :-)))
Sandy Bay, Hobart, Tas, AU.
Nov 14 '05 #6
Peter Williams wrote:

I can't quite figure out how to convert this line:

while(j != k)*((j -= w) + o) = f;


An alternative way to write this is...

while (j != k)
{
j = j - w;
j[o] = f;
}

--
Peter

Nov 14 '05 #7
On Sun, 06 Mar 2005 23:13:52 GMT, in comp.lang.c , "Peter Williams"
<pe*@bigpond.ne t.au> wrote:
Hi All,

I can't quite figure out how to convert this line:

while(j != k)*((j -= w) + o) = f;


it says
while j is not equal to k, set whatever is pointed to by (j-w+o) equal to
f, and subtract w from j.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Nov 14 '05 #8
"Peter Nilsson" <ai***@acay.com .au> writes:
Peter Williams wrote:

I can't quite figure out how to convert this line:

while(j != k)*((j -= w) + o) = f;


An alternative way to write this is...

while (j != k)
{
j = j - w;
j[o] = f;
}


Which requires pointer arithmetic. Last time I looked, Pascal didn't
support pointer arithmetic. Then again, the last time I looked was a
very long time ago.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #9
CBFalconer, Sun20050306@15: 00:05(CET):
Peter Williams wrote:

int c = 0, *n = v + 100, j = d < u - 1 ? a : - 9000, w, z,
i, g, q = 3-f;
IF d < u-l THEN j := a


Oops, that "l" should be a "1".
--
David Serrano
Nov 14 '05 #10

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

Similar topics

13
2509
by: dpj5754 | last post by:
Is there a simple and determinist way to make the difference between the 2 sequences: <XX></XX> and <XX/> The EndElement callback does not provide this information.
55
7318
by: Ton den Hartog | last post by:
Stupid basic question but I find it horribly imposible to find the answer elsewhere... :-( I want to have a piece of text in my HTML page and want to be able to change it in a Javascript function that is called from a button. I think I can use a <div id="t"></div> for this ? Something like
822
29875
by: Turamnvia Suouriviaskimatta | last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ , comp.realtime, comp.software-eng" groups regarding selection of a programming language of C, C++ or Ada for safety critical real-time applications. The majority of expert/people recommend Ada for safety critical real-time applications. I've many years of experience in C/C++ (and Delphi) but no Ada knowledge. May I ask if it is too difficult to move from C/C++ to Ada?...
5
2168
by: Ernesto | last post by:
Is there a way to compile a C program into a .pyc file that has the same behavior as the compiled C program? Thanks!
50
3021
by: strutsng | last post by:
I want if "a C program is a standard C++ program, but not vice versa" is a correct statement? In a C++ program, we can use standard C libraries. However, we cannot use C++ libraries inside C program. Please advise. thanks!!
63
15286
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html http://www.mailcom.com/ioccc/toledo/hint.htmBut this post is because I have discovered (asurprise for me) that it is also the worldsmallest chess program written in C language.It has a size of 3004 bytes, or 2261 bytes simplydeleting all the spacing that makes the knightfigure, cutting...
14
1386
by: Army1987 | last post by:
#include <string.h> #include <stdlib.h> #include <stdio.h> char *_(char *str1, char *str2) { char *res; res = malloc((strlen(str1)+strlen(str2))*sizeof(char)); strcpy(res, str1); strcpy(res+strlen(str1), str2); return res;
14
1701
by: Army1987 | last post by:
The following program compiles without errors or warnings with gcc -ansi -pedantic and works properly. #include <string.h> #include <stdlib.h> #include <stdio.h> char *f(char *str1, char *str2) { char *res = malloc(strlen(str1)+strlen(str2)+1); return res ? strcat(strcpy(res, str1), str2) : (exit(1), NULL);
18
2138
by: Ruud | last post by:
Hallo allemaal, In my Pascal program I gathered all messages in one function. All messages have their own number. One of the advantages of this method is that if someone wants to change a messages, he only has to look in one place. The function is declared as follow: function zin(by : byte) : string;
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.