The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Wednesday, November 28, 2012

Design and Implement a Calculator using ‘YACC’ and ‘LEX’


Calc.y

%{
#include <stdlib.h>
#include <stdio.h>
int yylex(void);
#include "y.tab.h"
%}

%token INTEGER

%%
program:
line program
| line

line:
expr '\n' { printf("%d\n",$1); }
| 'n'

expr:
expr '+' mulex { $$ = $1 + $3; }
| expr '-' mulex { $$ = $1 - $3; }
| mulex { $$ = $1; }

mulex:
mulex '*' term { $$ = $1 * $3; }
| mulex '/' term { $$ = $1 / $3; }
| term { $$ = $1; }

term:
'(' expr ')' { $$ = $2; }
| INTEGER { $$ = $1; }

%%
void yyerror(char *s)
{
fprintf(stderr,"%s\n",s);
return;
}
yywrap()
{
  return(1);
}

int main(void)
{
/*yydebug=1;*/
yyparse();
return 0;
}

Lexx.l

%{
#include <stdlib.h>
#include <stdio.h>
#include "y.tab.h"
void yyerror(char*);
extern int yylval;
%}


%%
[ \t]+ ;
[0-9]+ {yylval = atoi(yytext);
return INTEGER;}
[-+*/] {return *yytext;}
"(" {return *yytext;}
")" {return *yytext;}
\n {return *yytext;}
. {char msg[25];
sprintf(msg,"%s <%s>","invalid character",yytext);
yyerror(msg);}


Output :-

[S@localhost Desktop]$ flex lexx.l
[S@localhost Desktop]$ yacc -d calc.y
[S@localhost Desktop]$ gcc y.tab.c lex.yy.c
[S@localhost Desktop]$ ./a.out

5+6
11
8+9-7
10
6++9
syntax error
[S@localhost Desktop]$

Monday, November 26, 2012

Generate Three Address Code For Selected Statements


CODING :-

#include<stdio.h>
#include<string.h>

main()
{      
char str[10];
int i,j;
char op;
  printf(“\nEnter the expression:”);
scanf("%s",str);
op=str[0];
i=0;

while((op!='0')||(op!='+')||(op!='-')||(op!=’*’)||(op!=’/’))
{
op=str[++i];
}

switch(op)
{
case '+':printf("MOV R2,%c\n",str[i-1]);
printf("MOV R3,%c\n",str[i+1]);
printf("ADD R1,R2,R3\n");
printf("STORE R1,%c\n",str[i-3]);
break;
case '-':printf("MOV R2,%c\n",str[i-1]);
printf("MOV R3,%c\n",str[i+1]);
printf("SUB R1,R2,R3\n");
printf("STORE R1,%c\n",str[i-3]);
break;
                case '*':printf("MOV R2,%c\n",str[i-1]);
                         printf("MOV R3,%c\n",str[i+1]);
                         printf("MUL R1,R2,R3\n");
                         printf("STORE R1,%c\n",str[i-3]);
                         break;
                case '/':printf("MOV R2,%c\n",str[i-1]);
                         printf("MOV R3,%c\n",str[i+1]);
                         printf("DIV R1,R2,R3\n");
                         printf("STORE R1,%c\n",str[i-3]);
                         break;
default:printf("ERROR\n");
                break;
}
}

Output :-

Enter the expression: x=a+b

MOV R2,a
MOV R3,b
ADD R1,R2,R3
STORE R1,x


Saturday, November 24, 2012

To Generate A Parser For a Subset of ‘C’ Language Using ‘YACC’


CODING :-

%{
#include <stdio.h>
int regs[26];
int base;
%}

%start list

%token DIGIT LETTER

%left '|'
%left '&'
%left '+' '-'
%left '*' '/' '%'
%left UMINUS  /*supplies precedence for unary minus */

%%                   /* beginning of rules section */

list:                       /*empty */
         |
        list stat '\n'
         |
        list error '\n'
         {
           yyerror();
         }
         ;

stat:    expr
         {
           printf("%d\n",$1);
         }
         |
         LETTER '=' expr
         {
           regs[$1] = $3;
         }
         ;

expr:    '(' expr ')'
         {
           $$ = $2;
         }
         |
         expr '*' expr
         {
           $$ = $1 * $3;
         }
         |
         expr '/' expr
         {
           $$ = $1 / $3;
         }
         |
         expr '%' expr
         {

           $$ = $1 % $3;
         }
         |
         expr '+' expr
         {
           $$ = $1 + $3;
         }
|
         expr '-' expr
         {
           $$ = $1 - $3;
         }
         |
         expr '&' expr
         {
           $$ = $1 & $3;
         }
         |
         expr '|' expr
         {
           $$ = $1 | $3;
         }
         |

        '-' expr %prec UMINUS
         {
           $$ = -$2;
         }
         |
         LETTER
         {
           $$ = regs[$1];
         }

         |
         number
         ;

number:  DIGIT
         {
           $$ = $1;
           base = ($1==0) ? 8 : 10;
         }       |
         number DIGIT
         {
           $$ = base * $1 + $2;
         }
         ;
%%
main()
{
 return(yyparse());
}

yyerror(s)
char *s;
{
  fprintf(stderr, "%s\n",s);
}

yywrap()
{
  return(1);
}

Thursday, November 22, 2012

Create a 2-Pass 8085 Assembler


CODING :-

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

void gethex(int v,char*str)
{ str[3]=(v%16>9)?((v%16-10)+'A'):(v%16+'0');
  v=v/16;
  str[2]=(v%16>9)?((v%16-10)+'A'):(v%16+'0');
  v=v/16;
  str[1]=(v%16>9)?((v%16-10)+'A'):(v%16+'0');
  v=v/16;
  str[0]=(v%16>9)?((v%16-10)+'A'):(v%16+'0');
  str[4]='\0';
}

int main()
{
  char codes[100][2][100];
  int csize[100];
  int opos[100];
  int codemem[100];
  int tot=0,num=0,l=0;
  char str[100]="",ch;
  char*ptr=NULL;
  int i=0,j=0,k=0,fpos=0;

  for(i=1;i<=5;i++)
  for(j=1;j<=5;j++)
  if(i!=j)
  { strcpy(str,"MOV ");
    str[4]='A'+i-1;
    str[5]=',';
    str[6]='A'+j-1;
    str[7]='\0';
    strcpy(codes[tot][0],str);
    str[0]='A'+i-1;
    str[1]='A'+j-1;
    str[2]='\0';
    strcpy(codes[tot][1],str);
    csize[tot]=1;
    opos[tot]=0;
    tot++;
  }

  for(i=1;i<=5;i++)
  { strcpy(str,"ADD ");
    str[4]='A'+i-1;
    str[5]='\0';
    strcpy(codes[tot][0],str);
    str[0]='1';
    str[1]='A'+i-1;
    str[2]='\0';
    strcpy(codes[tot][1],str);
    csize[tot]=1;
    opos[tot]=0;
    tot++;
  }




  for(i=1;i<=5;i++)
  { strcpy(str,"LOAD ");
    str[5]='A'+i-1;
    str[6]='\0';
    strcpy(codes[tot][0],str);
    str[0]='2';
    str[1]='A'+i-1;
    //str[4]='H';
    str[2]='\0';
    strcpy(codes[tot][1],str);
    csize[tot]=2;
    opos[tot]=7;
    tot++;
  }  

  for(i=1;i<=5;i++)
  { strcpy(str,"SUB ");
    str[4]='A'+i-1;
    str[5]='\0';
    strcpy(codes[tot][0],str);
    //str[0]='0';
    //str[1]='4';
    str[0]='3';
    str[1]='A'+i-1;
    //str[4]='H';
    str[2]='\0';
    strcpy(codes[tot][1],str);
    csize[tot]=1;
    opos[tot]=0;
    tot++;
  }

  int jump=tot;
  strcpy(str,"JMP ");
  strcpy(codes[tot][0],str);
  strcpy(str,"06");
  strcpy(codes[tot][1],str);
  csize[tot]=3;
  opos[tot]=4;
  tot++;

  strcpy(str,"JNZ ");
  strcpy(codes[tot][0],str);
  strcpy(str,"07");
  strcpy(codes[tot][1],str);
  csize[tot]=3;
  opos[tot]=4;
  tot++;

  strcpy(str,"JZ ");
  strcpy(codes[tot][0],str);
  strcpy(str,"08");
  strcpy(codes[tot][1],str);
  csize[tot]=3;
  opos[tot]=3;
  tot++;

  strcpy(str,"JNC ");
  strcpy(codes[tot][0],str);
  strcpy(str,"09");
  strcpy(codes[tot][1],str);


  csize[tot]=3;
  opos[tot]=4;
  tot++;

  strcpy(str,"JC ");
  strcpy(codes[tot][0],str);
  strcpy(str,"0A");
  strcpy(codes[tot][1],str);
  csize[tot]=3;
  opos[tot]=3;
  tot++;
 
  char code[100][100];
  printf("\nTo end the code enter END\n");
  int size=0;
  while(1)
  { gets(code[size]);
    if(strcmp(code[size],"END")==0)
    break;
    size++;
  }

  char symb[100][2][100];
  int symbsize=0;
  int mempos=8192;

  for(i=0;i<size;i++)
  { int type=-1;
    int islabel=-1;
    for(j=0;code[i][j]!='\0';j++)
    if(code[i][j]==':')
    { islabel=j;
      break;
    }
    if(islabel!=-1)
    {
      for(j=0;j<islabel;j++)
      str[j]=code[i][j];
      str[j]='\0';
      strcpy(symb[symbsize][0],str);
      sprintf(str,"%d",mempos);
      strcpy(symb[symbsize][1],str);
      symbsize++;
    }
    else
    { for(j=0;j<tot;j++)
      { ptr=strstr(code[i],codes[j][0]);
        if(ptr!=NULL)
        { type=j;
         
          break;
        }
      }
      if(type==-1)
      { printf("\nIllegal Code\n");
        getch();
        exit(0);
      }
      mempos+=csize[type];
    }      
  }  



  mempos=8192;
  char output[100][100];
  int curs=0;

  for(i=0;i<size;i++)
  { int type=-1,islabel=-1;
    for(j=0;code[i][j]!='\0';j++)
    if(code[i][j]==':')
    { islabel=j;
      break; }
    if(islabel==-1)
    {
      for(j=0;j<tot;j++)
      { ptr=strstr(code[i],codes[j][0]);
        if(ptr!=NULL)
        { type=j;
          if(opos[j]==0)
          { strcpy(output[curs],codes[j][1]);
            codemem[curs]=mempos;
            mempos+=csize[j];
            curs++;
          }
          else if(opos[j]==7)
          { strcpy(output[curs],codes[j][1]);
            strcat(output[curs]," ");
            str[0]=code[i][opos[j]];
            str[1]=code[i][opos[j]+1];
            str[2]='\0';
            strcat(output[curs],str);
            codemem[curs]=mempos;
            mempos+=csize[j];
           
            curs++;
          }  
          else if(j>=jump)
          { strcpy(output[curs],codes[j][1]);
            strcat(output[curs]," ");
            for(k=opos[j];code[i][k]!='\0';k++)
            str[k-opos[j]]=code[i][k];
            str[k-opos[j]]='\0';
            fpos=-1;
            for(k=0;k<symbsize;k++)
            if(strcmp(symb[k][0],str)==0)
            { fpos=k;
              break;
            }
            if(fpos==-1)
            { printf("\nLabel named %s not defined\n",str);
              getch();
              exit(0);
            }
            num=0;
            for(l=0;l<4;l++)
            num=num*10+symb[k][1][l]-'0';
            gethex(num,str);
            ch=str[0];
            str[0]=str[2];
            str[2]=ch;
            ch=str[1];
            str[1]=str[3];
            str[3]=ch;
            strcat(output[curs],str);



            codemem[curs]=mempos;
            mempos+=csize[j];
            curs++;
          }
          break;  
        }
      }
    }
  }

  printf("\nMachine Code is\nMemory  Opcode+Operand\n");
  for(i=0;i<curs;i++)
  { gethex(codemem[i],str);
    printf("%s        %s\n",str,output[i]);
  }
  getch();
}


Input File:-

MOV A,B
MOV C,D
LOAD E,10H
MOV A,E
TEST:
ADD C
SUB D
JMP TEST
RUN:
ADD B
JC RUN
MOV D,E
JNC RUN
SUB A
JZ TEST
JNZ RUN
END

OUTPUT SCREEN:-

Machine Code is
Memory  Opcode+Operand
2000        AB
2001        CD
2002        2E 10
2004        AE
2005        1C
2006        3D
2007        06 0520
200A        1B
200B        0A 0A20
200E        DE
200F        09 0A20
2012        3A
2013        08 0520
2016        07 0A20


Tuesday, November 20, 2012

Create a Lexical Analyzer for a Subset of ‘C’ Language


CODING :-

%{                                                            
/* need this for the call to atof() below */
#include <math.h>
%}

DELIM  [ \t\n]
WHITESPACE {DELIM}+
DIGIT     [0-9]
LETTER  [a-zA-Z]
ID        {LETTER}({LETTER}|{DIGIT})*
NUMBER  {DIGIT}+(\.{DIGIT}+)?(e[+\-]?{DIGIT}+)?


%%
{DIGIT}+     {
             printf( "An integer: %s (%d)\n", yytext,
                     atoi( yytext ) );
             }
{DIGIT}+"."{DIGIT}*         {
             printf( "A float: %s (%g)\n", yytext,
                     atof( yytext ) );
             }
if|else|return|main|include|int|float|char         {
             printf( "A keyword: %s\n", yytext );
             }
{ID}         printf( "An identifier: %s\n", yytext );
"+"|"-"|";"|"="|"("|")"|"{"|"}"|"<"|">"|"*"|"/"    printf( "An operator: %s\n", yytext );

"{"[^}\n]*"}"      /* eat up one-line comments */
[ \t\n]+           /* eat up whitespace */
.            printf( "Unrecognized character: %s\n", yytext );
%%


main( argc, argv )
int argc;
char **argv;
    {
    ++argv, --argc; /* skip over program name */
    if ( argc > 0 )
             yyin = fopen( argv[0], "r" );
    else
             yyin = stdin;
    yylex();
    }

File.c

main()
{
int a1, a2;
float f1=9.09;
a1=10;
if(a1>10)
a2=a1;
}



OUTPUT SCREEN:-

[S@localhost ~]$ flex lex.l
[S@localhost ~]$ gcc -c lex.yy.c
[S@localhost ~]$ gcc -o final lex.yy.o -lfl
[S@localhost ~]$ ./final file.c

A keyword: main
An operator: (
An operator: )
An operator: {
A keyword: int
An identifier: a1
Unrecognized character: ,
An identifier: a2
An operator: ;
A keyword: float
An identifier: f1
An operator: =
A float: 9.09 (9.09)
An operator: ;
An identifier: a1
An operator: =
An integer: 10 (10)
An operator: ;
A keyword: if
An operator: (
An identifier: a1
An operator: >
An integer: 10 (10)
An operator: )
An identifier: a2
An operator: =
An identifier: a1
An operator: ;
An operator: }
[S@localhost ~]$

Wednesday, November 14, 2012

Implement Ceaser Substitution Cipher encryption and decryption technique

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

char mssg[100];
int k;
 
void get_mssg()
{
   printf("\n Enter the Plaintext (in caps): ");
   gets(mssg);
   printf("\n Enter the key (less than 26): ");
   scanf("%d",&k);
}

void en_mssg()
{
  int i = 0;
  while(mssg[i] != '\0')
  { 
    if(mssg[i] >= 65 && mssg[i] <= 90)          
     mssg[i] = ((mssg[i] - 65 + k) % 26)+65;
    i++;

  } 
  printf("\n The Ciphertext is : ");
  puts(mssg);
}

void de_mssg()
{
  int i = 0;
  while(mssg[i] != '\0')
  { 
    if(mssg[i] >= 65 && mssg[i] <= 90)    
    {    
      if((mssg[i]-65) >= k)
       mssg[i] = mssg[i] - k;
      else
       mssg[i] = 90-(k-(mssg[i]-65))+1;
    }     
    i++;
  } 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}


int main()
{
  get_mssg();  en_mssg();  de_mssg();
  return 0;
}

Tuesday, November 13, 2012

Implement Hill Substitution Cipher encryption and decryption technique

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

char mssg[100]; 
int k[][3] = { {17,17,5},
               {21,18,21},
               {2,2,19}
             }; 
         
int ki[][3] = { {4,9,15},
                {15,17,6},
                {24,0,17}
             }; 

int c[3];
int p[3];            
 
void get_mssg()
{
   printf("\n Enter the Plaintext (in caps): ");
   gets(mssg);
}

void multiply()
{
  for(int i=0;i<3;i++)
  {
   p[i] = 0;     
   for(int j=0;j<3;j++)
     p[i] += c[j]*k[i][j];
   p[i] %= 26;            
  }      
}

void multiply2()
{
  for(int i=0;i<3;i++)
  {
   c[i] = 0;     
   for(int j=0;j<3;j++)
     c[i] += p[j]*ki[i][j];
   c[i] %= 26;            
  }      
}

void en_mssg()
{
  int i = 0;
  while(i < strlen(mssg))
  {  
    c[0] = mssg[i]-65;
    if(mssg[i+1] == '\0')
      c[1] = c[2] = 0;
    else
    {
      c[1] = mssg[i+1]-65; 
      if(mssg[i+2] == '\0')
       c[2] = 0;
      else
       c[2] = mssg[i+2]-65;
    }
  
   multiply();



   int l =0;
   while(i<strlen(mssg) && l<3)
    mssg[i++] = p[l++]+65;         
   
  }  
  printf("\n The Ciphertext is : ");
  puts(mssg);
}

void de_mssg()
{
  int i = 0;
  while(i < strlen(mssg))
  {  
    p[0] = mssg[i]-65;
    if(mssg[i+1] == '\0')
      p[1] = p[2] = 0;
    else
    {
      p[1] = mssg[i+1]-65; 
      if(mssg[i+2] == '\0')
       p[2] = 0;
      else
       p[2] = mssg[i+2]-65;
    }
  
   multiply2();
   int l =0;
   while(i<strlen(mssg) && l<3)
    mssg[i++] = c[l++]+65;         
  } 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}

int main()
{
  get_mssg();
  en_mssg();
  de_mssg(); 
  getch();
  return 0; 
}

Monday, November 12, 2012

Implement Playfair substitution cipher encryption and decryption technique

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

char mssg[100]; 
char dmssg[200];
int ind[200];

char table[][5] = { {'M','O','N','A','R'}, {'C','H','Y','B','D'}, 
                    {'E','F','G','I','K'}, {'L','P','Q','S','T'}, 
                    {'U','V','W','X','Z'}
                  };
struct pos
{
  int i;
  int j;      
}a1,a2;
 
void get_mssg()
{
   printf("\n Enter the Plaintext (in caps): ");
   gets(mssg);
}

struct pos get_pos(char ch)
{
  struct pos t;
  for(t.i = 0; t.i < 5; t.i++)
  {
   for(t.j = 0; t.j < 5; t.j++)
   {
     if(table[t.i][t.j] == ch)
      return t;      
   }     
  }      
}

void set_pos(struct pos a1, struct pos a2, int & l)
{
  if(a1.i == a2.i)
  {
    dmssg[l] = table[a1.i][(a1.j+1)%5];    dmssg[l+1] = table[a2.i][(a2.j+1)%5];        
  }
  else if(a1.j == a2.j)
  {
    dmssg[l] = table[(a1.i+1)%5][a1.j];    dmssg[l+1] = table[(a2.i+1)%5][a2.j];        
  }
  else
  {
    dmssg[l] = table[a1.i][a2.j];          dmssg[l+1] = table[a2.i][a1.j]; 
  }     
}

void set_pos2(struct pos a1, struct pos a2, int & l)
{
  if(a1.i == a2.i)
  {
    mssg[l] = table[a1.i][a1.j == 0 ? 4 : a1.j-1];
    mssg[l+1] = table[a2.i][a2.j == 0 ? 4 : a2.j-1];        
  }

  else if(a1.j == a2.j)
  {
    mssg[l] = table[a1.i == 0 ? 4 : a1.i-1][a1.j];
    mssg[l+1] = table[a2.i == 0 ? 4 : a2.i-1][a2.j];        
  }
  else
  {
    mssg[l] = table[a1.i][a2.j];
    mssg[l+1] = table[a2.i][a1.j]; 
  }     
}

void en_mssg()
{
  int k =0,l = 0;
  while(k < strlen(mssg))
  {
    a1 = get_pos(mssg[k]);

    if(mssg[k+1] == '\0' || mssg[k+1] == mssg[k])
     a2 = get_pos( ((mssg[k] - 65 + 12) % 26)+65 );
    else
     a2 = get_pos(mssg[k+1]);
      
    set_pos(a1,a2,l);
   
    ind[l] = 0;
    if(mssg[k+1] == '\0' || mssg[k+1] == mssg[k])
    {
      ind[l+1] = 1;
      k++;           
    }
    else
    {
      ind[l+1] = 0;      
      k += 2; 
    }
    l += 2;         
  }  
  dmssg[l] = '\0';
  printf("\n The Ciphertext is : ");
  puts(dmssg);
}

void de_mssg()
{
  int k = 0;
  int l = 0;

  while(k < strlen(dmssg))
  {
    a1 = get_pos(dmssg[k]);   
    a2 = get_pos(dmssg[k+1]);
       
    set_pos2(a1,a2,l);
   
    if(ind[k+1] == 1)
     l += 1;   
    else
     l += 2;   
    k += 2;         
  }  
  mssg[l] = '\0';
 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}

int main()
{
  get_mssg();
  en_mssg();
  de_mssg(); 
  getch();
  return 0; 
}

Sunday, November 11, 2012

implement Transposition cipher encryption and decryption technique

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

char mssg[100],a[50],b[50],dmssg[100];
 
void get_mssg()
{
   printf("\n Enter the Plaintext : ");
   gets(mssg);
}

void en_mssg()
{
  int i=0,k=0,j;
 
  if(strlen(mssg)%2 == 0)
    j = strlen(mssg)/2;
  else
    j = strlen(mssg)/2+1;   
   
  while(i<strlen(mssg))
  {
   dmssg[k++] = mssg[i++];     

   if(mssg[i] == '\0')
    dmssg[j++] = '\0';        
   else
    dmssg[j++] = mssg[i++];  
  }  
  dmssg[i] = '\0';   
 
  printf("\n The Ciphertext is : ");
  puts(dmssg);
}

void de_mssg()
{
  int i=0,j,k=-1;
 
  if(strlen(dmssg)%2 == 0)
    j = strlen(dmssg)/2;
  else
    j = strlen(dmssg)/2+1; 
 
  int l = j;
  while(i < l && j < strlen(dmssg))
  {
    mssg[++k] = dmssg[i];   ++i;   mssg[++k] = dmssg[j];    ++j;         
  } 

  if(i<l)
   mssg[++k] = dmssg[i];
 
  printf("\n The Decrypted Plaintext is : ");
  puts(mssg);
}

int main()
{
  get_mssg();  en_mssg();  de_mssg(); 
  return 0; 
}

Saturday, November 10, 2012

implement S-AES BLOCK cipher encryption and decryption technique

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

unsigned char mssg[100];
unsigned char ch[2];
unsigned char rcon[] = {0x80,0x30};
int ind;
int k[3];

unsigned char nib[2][2];

unsigned char M[][2] = { {0x1,0x4},
                        {0x4,0x1}};

unsigned char IM[][2] = { {0x9,0x2},
                          {0x2,0x9}};

unsigned char SBox[][4] = { {0x9,0x4,0xA,0xB},
                           {0xD,0x1,0x8,0x5},
                           {0x6,0x2,0x0,0x3},
                           {0xC,0xE,0xF,0x7}};

unsigned char ISBox[][4] = { {0xA,0x5,0x9,0xB},
                            {0x1,0x7,0x8,0xF},
                            {0x6,0x0,0x2,0x3},
                            {0xC,0x4,0xD,0xE}};
               
                              
void get_mssg()
{
   printf("\n Enter the Plaintext : ");
   gets((char *)mssg);
}

void print_nib()
{
  printf("\n %x %x",nib[0][0],nib[0][1]);
  printf("\n %x %x",nib[1][0],nib[1][1]);  
}

void Nib_Sub(int ind)
{
  for(int i=0;i<2;i++)
  {
    for(int j=0;j<2;j++)
    {
      if(ind == 0)
        nib[i][j] = SBox[(nib[i][j] & 0xC)>>2][nib[i][j] & 0x3];
      else
        nib[i][j] = ISBox[(nib[i][j] & 0xC)>>2][nib[i][j] & 0x3];            
    }      
  } 
}

void Shift_Row()
{
  unsigned char tmp;
  tmp = nib[1][0];
  nib[1][0] = nib[1][1];
  nib[1][1] = tmp;     
}

void Mix_Col(int ind)
{
  unsigned char a,b;
  a = (ind == 0)? 0x1 : 0x9; 
  b = (ind == 0)? 0x4 : 0x2; 
 




  unsigned char tmp;
  tmp = nib[0][0];
  nib[0][0] = (a*tmp) xor (b*nib[1][0]);
  nib[1][0] = (b*tmp) xor (a*nib[1][0]);

  tmp = nib[0][1];
  nib[0][1] = (a*tmp) xor (b*nib[1][1]);
  nib[1][1] = (b*tmp) xor (a*nib[1][1]); 
}

void Make_Key(int& i)
{
  unsigned char cho[2],tcho;
 
  cho[0] = (k[i] & 0xFF00) >> 8;
  cho[1] = k[i] & 0x00FF;
 
  tcho = (SBox[(cho[1]&0xC0)>>6][(cho[1]&0x30)>>4]) |
((SBox[(cho[1]&0x0C)>>2][cho[1]&0x03])<< 4);
 
  cho[0] = cho[0] xor rcon[i] xor tcho;
  cho[1] = cho[0] xor cho[1];
 
  k[++i] = (cho[0]<<8) | cho[1]; 
}


void Add_Key(int i)
{
  nib[0][0] = nib[0][0] xor ((k[i] & 0xF000)>>12);
  nib[1][0] = nib[1][0] xor ((k[i] & 0x0F00)>>8);
  nib[0][1] = nib[0][1] xor ((k[i] & 0x00F0)>>4);
  nib[1][1] = nib[1][1] xor (k[i] & 0x000F);  
}

void enc_S_AES()
{
   int i = 0;

   nib[0][0] = (ch[0] & 0xF0)>>4;
   nib[1][0] = ch[0] & 0x0F;
   nib[0][1] = (ch[1] & 0xF0)>>4;
   nib[1][1] = ch[1] & 0x0F;
 
   k[0] = 0x2D55;
 
   Add_Key(i);
   while(i<2)
   {
     Shift_Row();
     Nib_Sub(0);   
     Mix_Col(0);
     Make_Key(i);
     Add_Key(i);        
   }
   
   ch[0] = (nib[0][0] << 4)| nib[1][0];
   ch[1] = (nib[0][1] << 4)| nib[1][1]; 
}

void dec_S_AES()
{
   int i = 2;
 
   nib[0][0] = (ch[0] & 0xF0)>>4;
   nib[1][0] = ch[0] & 0x0F;
   nib[0][1] = (ch[1] & 0xF0)>>4;
   nib[1][1] = ch[1] & 0x0F;
  
   Add_Key(i);
 
   while(i>0)
   {
     Nib_Sub(1);
     Shift_Row();
     Add_Key(--i);
     Mix_Col(1);             
   }
   


   ch[0] = (nib[0][0] << 4)| nib[1][0];
   ch[1] = (nib[0][1] << 4)| nib[1][1]; 
}

void en_mssg()
{
  int i = 0;
  int j = strlen((char *)mssg);
  ind = 0;

  while(i < j)
  {        
    ch[0] = mssg[i];

    if(mssg[i+1] == '\0')
    {
      ind = 1;
      ch[1] = ((mssg[i]- 65 + 12)% 26)+65;           
    }
    else
     ch[1] = mssg[i+1];
    enc_S_AES();
  
    mssg[i] = ch[0];
    mssg[i+1] = ch[1];          
    i += 2;
  }

  if(i > j)
   mssg[i] = '\0';
 
  printf("\n The Ciphertext is : ");
  puts((char *)mssg);
}

void de_mssg()
{
  int i = 0;
  int j = strlen((char *)mssg);
 
  while(i < j)
  {        
    ch[0] = mssg[i];
    ch[1] = mssg[i+1];
  
    dec_S_AES();
  
    mssg[i] = ch[0];
    mssg[i+1] = ch[1];          
    i += 2;
  }

  if(ind == 1)
   mssg[i-1] = '\0';
 
  printf("\n The Decrypted Plaintext is : ");
  puts((char *)mssg);
}

int main()
{
  get_mssg();
  en_mssg();
  de_mssg();
  getch();
  return 0;
}

Friday, November 9, 2012

Create Resume using HTML

<html>
<head></head>
<body>
<div style="width:900px; margin:auto">
<div style="height:150px">
<p style="font-size:50px; float:left; ">ASHISH BARDHAN(711/IT/09)</p>
<img src="NSIT-logo.jpg" height=150px align=right></img>
</div>


<div style="background:grey">
<p style="text-align:left; "><b>OBJECTIVE</b></p>
</div>

To enhance my technical and professional skills by working in a competitive industrial environment.

<div style="background:grey">
<p style="text-align:left; "><b>ACADEMIC QUALIFICATIONS</b></p>
</div>

<table style="border:5px solid;">
<tr>
<td width=275px>EXAMINATION</td>
<td width=125px>YEAR</td>
<td width=400px>Board/University</td>
<td width=100px>%/CGPA</td>
</tr>

<tr>
<td>B.E.(Information Technology)</td>
<td>2009-present</td>
<td>N.S.I.T. (formerly D.I.T.), University of Delhi</td>
<td>69.74%</td>
</tr>

<tr>
<td>AISSCE(Class XII)</td>
<td>2008</td>
<td>Shiv Vani Model Sr. Sec. School, New Delhi</td>
<td>84.6%</td>
</tr>

<tr>
<td>AISSE(Class X)</td>
<td>2006</td>
<td> Shiv Vani Model Sr. Sec. School, New Delhi </td>
<td>85.8%</td>
</tr>
</table>

<div style="background:grey">
<p style="text-align:left; "><b>ACADEMIC DISTINCTIONS</b></p>
</div>

<ul>
<li>Ranked among top 1.5% in DCE-CEE 2009 (ranked 399 in a pool of 35,000+ students).</li>
<li>Ranked School Top 10 in 10th Board Examination and 12th Board Examination.</li>
<li>Cleared Junior Level National Science Olympiad Contest 2005.</li>
<li>Awarded Merit Certificate in All India Talent Search Examination 2005.</li>
<li>Received School Scholar Certification and Badge for outstanding academic performance in 9th Standard.</li>
<li>Received School Certification of Merit for outstanding academic proficiency in 6th Standard.</li>

</ul>


<div style="background:grey">
<p style="text-align:left; "><b>KNOWLEDFE AND SKILLS</b></p>
</div>




C/C++ Programming Language (Proficient), Java (Core Basic), Data Structures, Object Oriented Technology, Computer Graphics, Operating Systems, Software Engineering, RDBMS, SQL, PHP, Computer Networks, Multimedia, Game Programming, Artificial Intelligence

<div style="background:grey">
<p style="text-align:left; "><b>PROJECTS</b></p>
</div>

<ul>
<li>
Comprehensive Secret Sharing Scheme for Mobile Ad-Hoc Networks (MANETs)                  (Oct’11-May’12)<br>
(Assisted Mrs. Amarjeet Malhotra, Lecturer, IT Deptt.,NSIT)
<ul>
<li>Discovered a Cryptographic secret sharing scheme for low end processing and limited resource power devices. </li>
<li>Accepted in 2012 IEEE International Symposium of Wireless Telecommunications and Applications (ISWTA), Indonesia.</li>
</ul>
</li>
<li>
Biclustering of Users’ data sets for their classification and further study of their common features<br>
(Assisted Mrs. Geeta Chikara in her research work. under the guidance of
Dr. Shampa Chakarvarty, HOD,COE Deptt., NSIT)
<ul>
<li>Classification is done on the basis of various attributes of users with a significant accuracy of about 90%. </li>
<li>The concept is being implemented on E-gov. systems for the users’ classification to provide them a more adaptive user interface.</li>
</ul>
</li>
<li>4-in-1 Video Game Pack Development                                           (April’12-May’12)        <br>
<ul>
<li>Developed a set of Four Video Games, using Turbo C/C++ Compiler and Standard BGI Graphics.</li>
</ul>
<li>Online Music Store Website Development                                                       (Oct’11-Nov’11)<br>
<ul>
<li>Developed a Website that allows users to purchase songs and create playlists, using PHP and MySQL.</li>
</ul>
</ul>

<div style="background:grey">
<p style="text-align:left; "><b>SUMMER INTERNSHIP</b></p>
</div>

<ul>
<li>Summer Intern, Career Connect International                                                    (June’12-July’12)<br>
<ul>
<li>Worked under the project “Internet Protocol Vulnerability Assessment for Public IP Address Range in Indian domain”. </li>
<li>Understood basics and performed practical on IP addresses, its vulnerabilities and its assessment tools and techniques.</li>
</ul>
</li>
</ul>


<div style="background:grey">
<p style="text-align:left; "><b>CURRICULAR ACHIEVEMENTS</b></p>
</div>

<ul>
<li>Participated in AI Challenge Competition at Innovision’10 and Innovsion‘11.</li>
<li>Participated in Inter-School Science and Computer Fair in 7th  and 8th Standard.</li>
<li>Participated in various Quiz and Writing Competitions at School Level.</li>
</ul>


<div style="background:grey">
<p style="text-align:left; "><b>EXTRA CURRICULAR ACHIEVEMENTS</b></p>
</div>



<ul>
<li>Participated in Freestyle Graffiti Battle at From The Roots Hip-Hop Jam (Vol. 1 and 2), Delhi.  </li>
<li>Participated and won various Fine Arts Competitions in Resonanz’09, Moksha’10 and Moksha’11.  </li>
<li>Worked under Fine Arts Department in Moksha’11 and Innovision’11 Inter-College Fests.</li>
<li>Participated in various LAN Gaming Tournaments during College Fests.</li>
<li>Participated in various Inter-School Sketching and Painting Competitions.</li>
<li>Won Intra-School House Volleyball Competition in 9th Standard.</li>
</ul>


<div style="background:grey">
<p style="text-align:left; "><b>INTRESTS</b></p>
</div>


Sketching, Painting, Photography, Music, Movies, Cartoons, Comedy Shows, Poetry, LAN Gaming, Cycling, Blogs, Net Surfing


<br><br><br><br>
<div>
<b><u>Email-id</u></b> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp ashbardhan@gmail.com
<br>
<u><b>Contact No.</b></u>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 9717741161
</div>

</div>
</body>
</html>

Thursday, November 8, 2012

design a form for creating an account in a social networking site using HTML


<html style="width:900px; margin:auto">
<body >
<form name=f action="">
<center><h2><u>USER DETAILS</u></h2></center>
<br>

<pre>
UserId              <input type=text name=t1 size=15><br> 
First Name          <input type=text name=t2 size=15><br>
Last Name           <input type=text name=t3 size=15><br>
Sex                 <input type=radio name=r  value=male>M<input type=radio name=r value=female>F<br>
E-MAIL              <input type=text name=t5 size=15><br>
Password            <input type=password name="pwd" size=15><br>
Confirm Password    <input type=password name="pwd" size=15><br>
Country             <input type=text name=t8 size=15> <br>
Birthday            <input type=text name="date" size=15 value="dd/mm/yy">
<input type=submit value="send"><input type=reset value="cancel">
</pre></form>

</body></html>

Wednesday, November 7, 2012

Design a Restaurant Menu using HTML

<html>
<head>
</head>
<body>
<div style="width:900px; margin:auto">
MENU CARD
<ol><li><b><u><h3>FOOD</h3></u></b></li>

<ul>
<li><b>Small Eats</b>
<dl>
<dt>Choco Doughnut&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 50/-</dt>
<dd>Bite into soft , sweet doughnut embraced with chocolate that takes you on a delicious roller coaster ride.</dd>
</dl>
<dl>
<dt>Veggie Samosa&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 10/-</dt>
<dd>Potatoes and pea cooked in south Indian spices and sealed fresh, served with home sauce.</dd>
</dl>
<dl>
<dt>Choco Brownie&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 30/-</dt>
<dd>The world's favourite dessert-choco cake with walnut. Chewy, gooey and wowie.</dd>
</dl>
<dl>
<dt>Spicy Chicken Calzone&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 60/-</dt>
<dd>Chicken sausage wrapped in a puff pastry with juicy onion & mustard.</dd>
</dl></li>

<li><b>Big Eats</b>
<dl>
<dt>Chicken Tikka Sandwich&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>Tender tandoori chicken tossed in zero trans-fat mayo, sandwiched in white bread.</dd>
</dl>
<dl>
<dt>Chicken Burger&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 50/-</dt>
<dd>Dig into the succulent chicken lapped with mayo cruncy coleslaw. Fun in a sesame bun!</dd>
</dl>
<dl>
<dt>Spinach Corn Sandwich&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>A delectable balance of creamy spinach cheese and juicy corn, satiates you with a homely touch. Best served grilled.</dd>
</dl></li>

<li><b>Sweet Eats</b>
<dl>
<dt>Choco Black Forest&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 35/-</dt>
<dd>Taste the familiar black forest crammed with chocolate mousse and cherries; and yet lighter and creamier.</dd>
</dl>
<dl>
<dt>Sizzle Dazzle Brownie&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>Sizzling hot gooey choco brownie served with vanilla ice cream and chocolate sauce. Fire and ice melt as one.</dd>
</dl>
<dl>
<dt>Chocolate Fantasy&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 45/-</dt>
<dd>A signature dessert….sinfully rich choclate cake. Try it with ice cream. Just make sure your friends are engrossed in a conversation.</dd>
</dl></li></ul>

<li><b><u><h3>BEVERAGES</h3></u></b></li>
<ul>
<li><b>Hot Coffees</b>
<dl>
<dt>Irish Coffee&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>Coffee, sugar, cream and the smooth flavour of non-alcoholic whiskey. The Irish Coffee.</dd>
</dl>
<dl>
<dt>Macchiato&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>Espresso's punch smoothened and mellowed by a dollop of foamed milk.</dd>
</dl>
<dl>
<dt>Espresso&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 30/-</dt>
<dd>The original Italian-strong and dark small but packs a punch. The Godfather of coffee.</dd>
</dl></li>

<li><b>Cold Coffees</b>
<dl>
<dt>Mochachillo&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 40/-</dt>
<dd>Rock your world with delicious combination of coffee and chocolate and chocolate poured over ice. Bye bye summer.</dd>
</dl>
<dl>
<dt>Devils Own&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;Rs- 50/-</dt>
<dd>Get wicked with the café frappe loaded with chocolate and whipped cream. Ah, so sinful!</dd>
</dl></li></ul>

</ol>
</div></body>
</html>

Tuesday, November 6, 2012

design a Web Page using Various links

<HTML>
<HEAD>

<META HTTP-EQUIV="refresh" CONTENT="5;URL=google.com">

</HEAD><BODY>
<a href="mailto:recipient@domain.com?cc=other@domain.com&bcc=hidden@domain.com&subject=Enquiry%20regarding%20product%20#0022">Email Us!</a>
<p>Create a link of an image:
<a href="default.asp"><img src="smiley.gif" alt="HTML tutorial" width="32" height="32"></a></p>
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
<p><a href="#C4">See also Chapter 4.</a></p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>
<h2><a id="C4">Chapter 4</a></h2>
<p>This chapter explains ba bla bla</p>
</BODY></HTML>


Sunday, November 4, 2012

design a Web Page showing schedule of a railway station using Inline CSS

<html>
<head>
<title>train</title>
<style type="text/css">
body {
color:red;}
</style>
</head>
<body style="background-color:gold">
<img src="railway.jpg" align="left" width="250px" height="250px">
<h2 style="color:red"><center>TRAIN SCHEDULE</center></h2>
<table border="1" width="100px" height="150px" align="center">
<tr style="color:black">
<td style="text-weight:bold">S.No.</td>
<td style="text-weight:bold">Name of the Train</td>
<td style="text-weight:bold">Arrival Time</td>
<td style="text-weight:bold">Depart Time</td>
<td style="text-weight:bold">Delayed/On-time</td>
</tr>
<tr>
<td>1</td>
<td>Shatabadi Express</td><td>9 a.m.</td><td>9:30 a.m.</td><td>On time</td>
</tr>
<tr>
<td>2</td>
<td>Rajnikant Express</td><td>11 a.m.</td><td>11:05 a.m.</td><td>On time</td>
</tr>
<tr>
<td>3</td>
<td>Dhoom Express</td><td>2 p.m.</td><td>2:10 p.m.</td><td>Delayed</td>
</tr>
<td>3</td>
<td>Dhoom Express</td><td>2 p.m.</td><td>2:10 p.m.</td><td>Delayed</td>
</tr>
<td>3</td>
<td>Dhoom Express</td><td>2 p.m.</td><td>2:10 p.m.</td><td>Delayed</td>
</tr>
</table>
</body>
</html>

Saturday, November 3, 2012

design a Web Page on Indian Tourism Using Embedded CSS

<html>
<head>
<title>INDIAN TOURISM</title>
<style type="text/css">

body {
  background-image:url("tourism.jpg");
}

h2 {
color:gold;
}
h4 {
color:black;
}
</style>
</head>
<body>
<h2>INDIAN TOURISM</h2><br>
<h4>Come, seek and be discovered. Match India's rhythms to your heart,
<br> its colours to your mind, and find a travel experience that is yours alone.
<br> An India like no other. Friendly, warm, welcoming ... and
<br> uniquely your own.Travel Trade Media
</h4> 
</body>
</html>

Friday, November 2, 2012

design an External CSS and export to various web pages that can be viewed simultaneously

Main.html

<html>
<head>
</head>

<body>
<div style="width:900px; margin:auto">
<iframe src="page1.html" width=400px height=300px margin=10 20></iframe>
<iframe src="page2.html" width=400px height=300px ></iframe>
<iframe src="page3.html" width=800px height=250px></iframe>
</div>
</body>

</html>

style.css

.para1{
color:blue;
font-size:20px;
font-family:verdana;
}

.para2{
color:black;
font-size:25px!important;
font-family:arial;
}

.para3{
color:Indigo  ;
font-size:15px!important;
font-family:comic sans ms;
}

Page1.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"  />
</head>

<body>
<p class="para1">Using sophisticated computer modelling, they found
 these fast-moving stars, known as the Orion Nebula Cluster, were potentially
 held together by the gravitational pull of a black hole
 up to 200 times the mass of the Sun.
<br><br>
Formed one or two million years ago, the cluster has long been
known for its strange properties. Its stars move at a rapid speed,
as if the whole cluster was flying apart, reported the Astrophysical Journal.
</p>
</body>

</html>

Page2.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"  />
</head>

<body>
<p class="para2">
Compared to the number of light-weight stars
that can be seen in the cluster, the number of heavy-weight
 stars are too few and especially rapidly-moving, according to a Queensland statement.




<br><br>
"These properties have been a puzzle to astronomers,
 given all the knowledge that they have about how stars
 are formed and distributed," said Holger Baumgardt from the University of
 Queensland's School of Mathematics and Physics, who co-authored the study.
 </p>
</body>

</html>

Page3.html


<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"  />
</head>

<body>
<p class="para3">
"In our model, we had to invent a new method
 of dealing with the gas and the way it is driven
 out from the cluster by the intensely radiating
 high-mass (heavy weight) stars," said Ladislav Subr,
 of Charles University in Prague, who led the study.
<br><br>
Many of the heavy stars were sling-shot out of the cluster, while some were driven into the centre of the cluster and collided with the most massive star there.
<br><br>
At some point, this massive star became unstable and imploded into a black hole, with a mass about 200 times larger than the Sun.<br><br>"Our scenario neatly accounts for virtually all observed properties of the Orion Nebula Cluster, that is, its low number of high-mass stars, and its rapidly-moving central stars, and suggests that the massive stars
 near the centre of this cluster are bound by a black hole," Subr said
</p>
</body>

</html>