Industrial Training




Cryptic Code

Cryptic programs are those programs which are very difficult to understand. Writing cryptic programs in C is fun as well as challenging. Here we are presenting some cryptic C programs. We are sure that these programs would challenge your skills and understanding of C language. Execute these programs and enjoy.

 

Producing Code As Output


 

This program on execution produces its own source code as the output. This program uses trigraph so that it can be portable to machines with deficient character sets from C's standpoint.

char*a??(??)=??<
"??=include<stdio.h>",
"??=include<stdlib.h>",
"??=define o stdout",
"??=define b break;case",
"??=define s(p)fputs(p,o);",
"??=define c(p)fputc(p,o);",
"void t(char*p,int f)??<f&&c('??/"')",
"for(;;p++)??<switch(*p)??<case 0:f&&",
"s(??/"??/??/??/",??/")c('??/??/n')return;case",
"'??=':s(??/"???/??/?=??/")b'??<':s(??/"???/??/?<??/")",
"b'??>':s(??/"???/??/?>??/")b'??(':s(??/"???/??/?(??/")b'??)'",
":s(??/"???/??/?)??/")b'??/??/??/??/':f&&s(??/"???/??/?/??/")",
"s(??/"???/??/?/??/")b'??/??/n':if(f)s(??/"???/??/?/n??/")",
"else case'??/"':if(f)s(??/"???/??/?/??/??/??/"??/")",
"else default:c(*p)??>??>??>main()??<char**p",
";t(??/"char*a??(??)=??<??/",0);for(p=a;*p",
";p++)t(*p,1);t(??/"0??>;??/",0);for(p=a",
";*p;p++)t(*p,0);exit(!ferror(o)&&",
"!fclose(o)?EXIT_SUCCESS",
":EXIT_FAILURE);",
"/*NOTREACHED*/",
"??>",
0??> ;
??=include<stdio.h>
??=include<stdlib.h>
??=define o stdout
??=define b break;case
??=define s(p)fputs(p,o);
??=define c(p)fputc(p,o);
void t(char*p,int f)??<f&&c('"')
for(;;p++)??<switch(*p)??<case 0:f&&
s("??/",")c('??/n')return;case
'??=':s("???/?=")b'??<':s("???/?<")
b'??>':s("???/?>")b'??(':s("???/?(")b'??)'
:s("???/?)")b'??/??/':f&&s("???/?/")
s("???/?/")b'??/n':if(f)s("???/?/n")
else case'"':if(f)s("???/?/??/"")
else default:c(*p)??>??>??>main()??<char**p
;t("char*a??(??)=??<",0);for(p=a;*p
;p++)t(*p,1);t("0??>;",0);for(p=a
;*p;p++)t(*p,0);exit(!ferror(o)&&
!fclose(o)?EXIT_SUCCESS
:EXIT_FAILURE);
/*NOTREACHED*/
??>

Loves me, Loves me not


On execution the program prints loves me, loves me not on the screen. Have a look at the program and you won't have the slightest of clues about the output. But then, that's what cryptic code is all about.

char *lie;
double time, me= !0XFACE,
not; int rested, get, out;
main(ly, die ) char ly, **die ;{
signed char lotte,
dear; ( char ) lotte-- ;
for(get= !me;; not){
1 - out & out ;lie;{
char lotte, my= dear,
**let = !!me *!not+ ++die ;
(char*) (lie =
"The gloves are OFF this time, I detest you, snot\n\0sed GEEK!");
do{not= *lie++ & 0xF00L* !me ;
#define love (char*)lie -
love 1 *! (not= atoi(let
[get -me?
(char) lotte-
(char) lotte: my- *love -
'I' - *love- 'U'-
'I' - (long) - 4 - 'U'])- !!
(time =out= 'a'));} while(my - dear
&& 'I'-1l -get- 'a'); break;}}
(char)*lie++;
(char)*lie++, (char)*lie++; hell:0, (char)*lie;
get *out* (short)ly -0-'R'- get- 'a'^rested;
do {auto*eroticism,
that; puts(*( out
-'c'
-('p'-'S') +die+ -2));}while(!"you're at it");
for (*((char*)&lotte)^=
(char) lotte; (love ly) [(char)++lotte+
!!0xBABE];) {if ('I' -lie[ 2+ (char) lotte]){ 'I'- 1l ***die;}
else{ if('I' * get *out* ('I'-1l **die[ 2 ])) * ((char*)&lotte) -=
'4' - ('I'-1l); not; for (get=!
get; !out; (char)*lie & 0xD0- !not) return!!
(char) lotte;}
(char)lotte;
do{ not* putchar(lie [out
*!not* !!me +(char)lotte]);
not; for(;!'a';);}while(
love (char*)lie);{
register this;
switch ( (char)( lie [(char) lotte]- 1 *!out))
{
char*les, get= 0xFF, my; case' ':
*((char*)&lotte) += 15; !not+ (char)*lie*'s';
this +1+ not; default: 0xF +(char*) lie;}}}
get - !out;
if (not--)
goto hell;
exit( (char)lotte);}

 

The 8 Queens

This program shows how to place 8 queens on a chessboard such that no queen can take/kill the other. The code seems bizarre. But it works fine. On execution you need to supply the size of your chessboard to the scanf( ) statement. You can supply any number between 4 and 99. If you supply 5, then it assumes that you are working with a 5 x 5 chess-board with 5 queens. What you are likely to appreciate is it gives all possible solutions in the output. The following figure shows one of the possible solutions for a 8 x 8 chessboard.


int v,i,j,k,l,s,a[99];
main( )
{
for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<
s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&
++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++
a[i])>=s*k&&++a[--i]) ;
}



Hi I am Pluto.