can u explain this code?

Discussion in 'C Programming' started by kartheeknagasuri@gmail.com, Aug 8, 2006.

  1. Guest

    my friend gave this code to me..... it is working fine....how come?

    please explain me if u can understand.....

    #include <stdio.h>
    #include <conio.h>


    #define _(__,___)\
    ___##__
    _(id,vo) _8(_(
    ar,ch)a,_(ar ,ch
    )*_2){_(ile,wh) (a
    --)_(ntf, pri)("%s"
    ,_2);}_(id,vo) _1(_
    (nt,i) s,_(nt,i) n,
    _(nt,i) k=1,_(ar,ch
    ) *_3="* "){_8 ( k,
    "\n");_8(s," ");_8(
    n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    {240,32,0},_4;_1(20,3,6);_1(19,1)
    ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    _22);_1(1,1,0);_1(19,1);
    _1(4,1,0);_1(15,8);
    _1(13,10);_1(0,1,0,"*");_
    (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}
     
    , Aug 8, 2006
    #1
    1. Advertising

  2. said:

    > my friend gave this code to me..... it is working fine....how come?


    foo.c:2: conio.h: No such file or directory

    Looks like it doesn't work fine after all.

    And even if you ignore that, it gets the entry point's return type wrong, so
    the behaviour of the program is undefined. There's nothing even remotely
    fine about this program.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Aug 8, 2006
    #2
    1. Advertising

  3. On Tue, 8 Aug 2006 wrote:

    > my friend gave this code to me..... it is working fine....how come?
    >
    > please explain me if u can understand.....
    >
    > #include <stdio.h>
    > #include <conio.h>
    >
    >
    > #define _(__,___)\
    > ___##__
    > _(id,vo) _8(_(
    > ar,ch)a,_(ar ,ch
    > )*_2){_(ile,wh) (a
    > --)_(ntf, pri)("%s"
    > ,_2);}_(id,vo) _1(_
    > (nt,i) s,_(nt,i) n,
    > _(nt,i) k=1,_(ar,ch
    > ) *_3="* "){_8 ( k,
    > "\n");_8(s," ");_8(
    > n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    > l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    > ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    > vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    > "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    > {240,32,0},_4;_1(20,3,6);_1(19,1)
    > ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    > _22);_1(1,1,0);_1(19,1);
    > _1(4,1,0);_1(15,8);
    > _1(13,10);_1(0,1,0,"*");_
    > (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    > 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    > or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    > 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}


    Nonportabilities [1] aside, the actual obfuscation here is
    fairly simple: #define _(__,___) ___##__ concatenates its two
    arguments in reverse. Thus, _(id,vo) gives gives you void,
    _(ar,ch)*_2 gives you char*_2 (and so forth).

    Tak-Shing

    [1] I would leave it to the pedants to enumerate them.
     
    Tak-Shing Chan, Aug 8, 2006
    #3
  4. Morris Dovey Guest

    Tak-Shing Chan (in
    ) said:

    | On Tue, 8 Aug 2006 wrote:
    |
    || my friend gave this code to me..... it is working fine....how come?
    ||
    || please explain me if u can understand.....
    ||
    || #include <stdio.h>
    || #include <conio.h>
    ||
    ||
    || #define _(__,___)\
    || ___##__
    || _(id,vo) _8(_(
    || ar,ch)a,_(ar ,ch
    || )*_2){_(ile,wh) (a
    || --)_(ntf, pri)("%s"
    || ,_2);}_(id,vo) _1(_
    || (nt,i) s,_(nt,i) n,
    || _(nt,i) k=1,_(ar,ch
    || ) *_3="* "){_8 ( k,
    || "\n");_8(s," ");_8(
    || n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    || l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    || ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    || vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu?" "t,nq"
    || "?,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    || {240,32,0},_4;_1(20,3,6);_1(19,1)
    || ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    || _22);_1(1,1,0);_1(19,1);
    || _1(4,1,0);_1(15,8);
    || _1(13,10);_1(0,1,0,"*");_
    || (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    || 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    || or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    || 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}
    |
    | Nonportabilities [1] aside, the actual obfuscation here is
    | fairly simple: #define _(__,___) ___##__ concatenates its two
    | arguments in reverse. Thus, _(id,vo) gives gives you void,
    | _(ar,ch)*_2 gives you char*_2 (and so forth).
    |
    | Tak-Shing
    |
    | [1] I would leave it to the pedants to enumerate them.

    Ugh, not pretty! With liberal renaming I got:

    #include <stdio.h>
    #include <conio.h>

    void fna(char a,char *s)
    { while (a--) printf("%s",s);
    }

    void fnb(int k,int l,char *9)
    { fna(k,"\n");
    fna(l, " ");
    while(*9) printf("%c",*9++-12);
    }

    void fnc(int s,int n,int k=1,char *t="* ")
    { fna(k,"\n");
    fna(s," ");
    fna(n,t);
    }

    void main()
    { char v1[] = "cu?t,nq?,~qsm~p8",
    v2[] = "X{wm",
    v3[] = { 240,32,0 },
    i;

    fnc(20,3,6);
    fnc(19,1);
    fnc(4,1,0);
    fnc(19,1);
    fnc(1,1, 0,v3);
    fnc(1,1,0);
    fnc(19,1);
    fnc(4,1,0);
    fnc(15,8);
    fnc(13,10);
    fnc(0,1,0,"*");
    for (i=0; i<4; i++)
    { fnc(15+i*2,8-i*2);
    if (i==0) fnc(0,2,0," *");
    }
    for (i=2; i>=0; i--) fnc(15+i*2,8-i*2);
    fnb(3,26,v1);
    fnb(2,40,v2);
    while (!kbhit()) ;
    }

    Left as an exercise for the OP to enumerate the problems.

    --
    Morris Dovey
    DeSoto Solar
    DeSoto, Iowa USA
    http://www.iedu.com/DeSoto
     
    Morris Dovey, Aug 8, 2006
    #4
  5. writes:
    > my friend gave this code to me..... it is working fine....how come?
    >
    > please explain me if u can understand.....


    "u" doesn't read this newsgroup. If you meant "you", please say so.
    Silly abbreviations like "u" for "you" are discouraged here.

    > #include <stdio.h>
    > #include <conio.h>


    This is a system-specific header.

    >
    > #define _(__,___)\
    > ___##__


    The identifiers __ and ___ are reserved to the implementation.

    Leaving that aside, the macro takes two arguments and pastes them
    together in reverse order. For example, "_(id,vo)" expands to "void".

    > _(id,vo) _8(_(
    > ar,ch)a,_(ar ,ch
    > )*_2){_(ile,wh) (a

    [snip]

    It's not worth my time to wade through all that noise. If you're
    curious find out if your compiler has an option to show you the output
    of the preprocessor. Coment out the #include directives so it doesn't
    insert the contents of those headers into the output.

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Aug 8, 2006
    #5
  6. Keith Thompson wrote:
    > writes:
    >> #define _(__,___)\
    >> ___##__

    >
    > The identifiers __ and ___ are reserved to the implementation.


    Even as macro arguments? On comp.std.c I was told that

    #if 0
    __special
    #endif
    int main(void) {}

    and

    #ifdef __special
    /* nothing */
    #endif
    int main(void) {}

    are both strictly conforming -- essentially because __special is only
    reserved for "any" use after preprocessing. During preprocessing, it is
    reserved for use as a macro name, but not for anything beyond that unless
    it doesn't affect any (otherwise) strictly conforming program. Since naming
    your macro arguments __ and ___ prevents any predefined macros __ and ___
    from being expanded, I think that should be fine.
     
    Harald van =?UTF-8?B?RMSzaw==?=, Aug 8, 2006
    #6
  7. Harald van Dijk <> writes:
    > Keith Thompson wrote:
    >> writes:
    >>> #define _(__,___)\
    >>> ___##__

    >>
    >> The identifiers __ and ___ are reserved to the implementation.

    >
    > Even as macro arguments? On comp.std.c I was told that
    >
    > #if 0
    > __special
    > #endif
    > int main(void) {}
    >
    > and
    >
    > #ifdef __special
    > /* nothing */
    > #endif
    > int main(void) {}
    >
    > are both strictly conforming -- essentially because __special is only
    > reserved for "any" use after preprocessing. During preprocessing, it is
    > reserved for use as a macro name, but not for anything beyond that unless
    > it doesn't affect any (otherwise) strictly conforming program. Since naming
    > your macro arguments __ and ___ prevents any predefined macros __ and ___
    > from being expanded, I think that should be fine.


    You may be right; I'm not sure. (I avoid the issue by avoiding
    identifiers starting with '_' altogether.)

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Aug 8, 2006
    #7
  8. Michael Mair Guest

    Harald van Dijk schrieb:
    > Keith Thompson wrote:
    >
    >> writes:
    >>
    >>>#define _(__,___)\
    >>>___##__

    >>
    >>The identifiers __ and ___ are reserved to the implementation.

    >
    > Even as macro arguments? On comp.std.c I was told that
    >
    > #if 0
    > __special
    > #endif
    > int main(void) {}
    >
    > and
    >
    > #ifdef __special
    > /* nothing */
    > #endif
    > int main(void) {}
    >
    > are both strictly conforming -- essentially because __special is only
    > reserved for "any" use after preprocessing. During preprocessing, it is
    > reserved for use as a macro name, but not for anything beyond that unless
    > it doesn't affect any (otherwise) strictly conforming program. Since naming
    > your macro arguments __ and ___ prevents any predefined macros __ and ___
    > from being expanded, I think that should be fine.


    Predefined macro names must not be the subject of a #define or
    #undef directive; i.e. #define __(_,___) ___##_ would not have
    been allowed as _ followed by an uppercase letter or _ belongs to
    the "implementation namespace" for predefined macro names. (C99,
    6.10.8#4)
    Identifiers starting with _ followed by an uppercase letter or
    _ are always reserved for any use, identifiers starting with
    _ followed by a lowercase letter are reserved for file scope
    (ordinary and tag namespace) identifiers. (C99, 7.10.3#1)
    As macro names are identifiers (C99, 6.2.1#1), I'd say you are
    right.


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
     
    Michael Mair, Aug 8, 2006
    #8
  9. MQ Guest

    wrote:
    > my friend gave this code to me..... it is working fine....how come?
    >
    > please explain me if u can understand.....
    >
    > #include <stdio.h>
    > #include <conio.h>
    >
    >
    > #define _(__,___)\
    > ___##__
    > _(id,vo) _8(_(
    > ar,ch)a,_(ar ,ch
    > )*_2){_(ile,wh) (a
    > --)_(ntf, pri)("%s"
    > ,_2);}_(id,vo) _1(_
    > (nt,i) s,_(nt,i) n,
    > _(nt,i) k=1,_(ar,ch
    > ) *_3="* "){_8 ( k,
    > "\n");_8(s," ");_8(
    > n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    > l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    > ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    > vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    > "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    > {240,32,0},_4;_1(20,3,6);_1(19,1)
    > ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    > _22);_1(1,1,0);_1(19,1);
    > _1(4,1,0);_1(15,8);
    > _1(13,10);_1(0,1,0,"*");_
    > (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    > 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    > or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    > 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}


    Yikes, someone has too much spare time....
     
    MQ, Aug 9, 2006
    #9
  10. Guest

    wrote:
    > my friend gave this code to me..... it is working fine....how come?
    >
    > please explain me if u can understand.....
    >
    > #include <stdio.h>
    > #include <conio.h>
    >
    >
    > #define _(__,___)\
    > ___##__
    > _(id,vo) _8(_(
    > ar,ch)a,_(ar ,ch
    > )*_2){_(ile,wh) (a
    > --)_(ntf, pri)("%s"
    > ,_2);}_(id,vo) _1(_
    > (nt,i) s,_(nt,i) n,
    > _(nt,i) k=1,_(ar,ch
    > ) *_3="* "){_8 ( k,
    > "\n");_8(s," ");_8(
    > n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    > l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    > ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    > vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    > "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    > {240,32,0},_4;_1(20,3,6);_1(19,1)
    > ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    > _22);_1(1,1,0);_1(19,1);
    > _1(4,1,0);_1(15,8);
    > _1(13,10);_1(0,1,0,"*");_
    > (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    > 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    > or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    > 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}


    If u have many spare time. u can find all the code on IOCCC. This
    place u can find what u want, hah
     
    , Aug 9, 2006
    #10
  11. Guest

    i am very thankful to u sir......



    Tak-Shing Chan wrote:
    > On Tue, 8 Aug 2006 wrote:
    >
    > > my friend gave this code to me..... it is working fine....how come?
    > >
    > > please explain me if u can understand.....
    > >
    > > #include <stdio.h>
    > > #include <conio.h>
    > >
    > >
    > > #define _(__,___)\
    > > ___##__
    > > _(id,vo) _8(_(
    > > ar,ch)a,_(ar ,ch
    > > )*_2){_(ile,wh) (a
    > > --)_(ntf, pri)("%s"
    > > ,_2);}_(id,vo) _1(_
    > > (nt,i) s,_(nt,i) n,
    > > _(nt,i) k=1,_(ar,ch
    > > ) *_3="* "){_8 ( k,
    > > "\n");_8(s," ");_8(
    > > n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    > > l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    > > ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    > > vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    > > "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    > > {240,32,0},_4;_1(20,3,6);_1(19,1)
    > > ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    > > _22);_1(1,1,0);_1(19,1);
    > > _1(4,1,0);_1(15,8);
    > > _1(13,10);_1(0,1,0,"*");_
    > > (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    > > 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    > > or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    > > 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}

    >
    > Nonportabilities [1] aside, the actual obfuscation here is
    > fairly simple: #define _(__,___) ___##__ concatenates its two
    > arguments in reverse. Thus, _(id,vo) gives gives you void,
    > _(ar,ch)*_2 gives you char*_2 (and so forth).
    >
    > Tak-Shing
    >
    > [1] I would leave it to the pedants to enumerate them.
    > ---559023410-851401618-1155060259=:7062--
     
    , Aug 9, 2006
    #11
  12. On 2006-08-09, MQ <> wrote:
    >
    > wrote:
    >> my friend gave this code to me..... it is working fine....how come?
    >>
    >> please explain me if u can understand.....
    >>
    >> #include <stdio.h>
    >> #include <conio.h>
    >>
    >>
    >> #define _(__,___)\
    >> ___##__
    >> _(id,vo) _8(_(
    >> ar,ch)a,_(ar ,ch
    >> )*_2){_(ile,wh) (a
    >> --)_(ntf, pri)("%s"
    >> ,_2);}_(id,vo) _1(_
    >> (nt,i) s,_(nt,i) n,
    >> _(nt,i) k=1,_(ar,ch
    >> ) *_3="* "){_8 ( k,
    >> "\n");_8(s," ");_8(
    >> n,_3);}_(id,vo) _6(_(nt,i) k,_(nt,i)
    >> l,_(ar,ch) *_9_){_8(k,"\n");_8(l, " ");_(ile
    >> ,wh)(*_9_)_(ntf,pri)("%c",*_9_++-12);} _(id,
    >> vo) _(in,ma)(){_(ar,ch) _1_1_[]="cu€" "t,nq"
    >> "€,~qsm~p8",_2_2_[]="X{wm";_(ar,ch) _22[]=
    >> {240,32,0},_4;_1(20,3,6);_1(19,1)
    >> ;_1(4,1,0);_1(19,1); _1(1,1, 0,
    >> _22);_1(1,1,0);_1(19,1);
    >> _1(4,1,0);_1(15,8);
    >> _1(13,10);_1(0,1,0,"*");_
    >> (or,f)(_4=0;_4<4;_4++) {_1(15+_4*2,
    >> 8-_4*2);_(f,i)(_4==0) _1(0,2,0," *");}_(
    >> or,f)(_4=2;_4>=0;_4--)_1(15+_4*2,8-_4*2);_6(3,
    >> 26,_1_1_);_6(2,40,_2_2_);_(ile,wh)(!_(it,kbh)());}

    >
    > Yikes, someone has too much spare time....
    >


    Time that would better be spent learning C. There's no such thing
    as "conio.h" in standard C. (I'm ignoring the various actual code
    problems others have pointed out.)

    --
    Andrew Poelstra <http://www.wpsoftware.net/projects>
    To reach me by email, use `apoelstra' at the above domain.
    "Do BOTH ends of the cable need to be plugged in?" -Anon.
     
    Andrew Poelstra, Aug 12, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. suzy
    Replies:
    3
    Views:
    466
  2. srikanth
    Replies:
    14
    Views:
    554
    vijay
    Jul 10, 2003
  3. Sid
    Replies:
    3
    Views:
    451
  4. Replies:
    2
    Views:
    566
    ACE01
    Nov 7, 2006
  5. Jia Lu
    Replies:
    1
    Views:
    284
    Gabriel Genellina
    Feb 11, 2007
Loading...

Share This Page