Wednesday 20 April 2011

Re: BA Lab Program By Pervez Alam for everyone ;-)

#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>
#include<math.h>

#define xi 0
#define xl 639
#define yi 1
#define yl 479

#define lin 21
#define rec 22
#define cir 23
#define pen 24
#define ter 25
#define dec 26
#define dly 27
#define del 28
#define dio 29
#define mem 30

union REGS i,o;
int initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}

void showmouseptr(void)
{
i.x.ax=1;
int86(0x33,&i,&o);
}

void hidemouseptr(void)
{
i.x.ax=2;
int86(0x33,&i,&o);
}

void restrictmouseptr(int x1,int y1,int x2,int y2)
{
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}


void getmousepos(int *button,int *x,int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}
void drawLayout()
{
setcolor(BLUE);
rectangle(xi+3,yi+3,xl-3,yi+20);
setcolor(GREEN);
outtextxy(10,10,"-- Flow-Chart Generator --");
setcolor(BLACK);
outtextxy(625,9,"X");
drawPad();
colorPad();
toolBox();
}
int toolBox()
{ int a,x1,y1;
setcolor(BLUE);
outtextxy(16,290,"TOOLS");
setcolor(DARKGRAY);
for(a=0;a<5;a++)
{ rectangle(xi+4,yi+300+a*30,xi+30,yi+300+26+a*30);
rectangle(xi+40,yi+300+a*30,xi+40+26,yi+25+300+a*30);
}
setcolor(BLACK);
line(8,304,26,322);
setcolor(BLUE);
line(8,303,26,321);
setcolor(MAGENTA);
line(8,305,26,323);
setcolor(BLACK);
rectangle(44,304,62,322);
setfillstyle(1,LIGHTBLUE);
floodfill(46,306,BLACK);
setcolor(BLACK);
circle(17,344,10);
setfillstyle(1,LIGHTCYAN);
floodfill(17,344,BLACK);
x1=40; y1=332;
setcolor(RED);
setlinestyle(0, 1, 3);
line(19+x1, 21+y1, 10+x1, 9+y1);
setlinestyle(0, 1, 1);
line(11+x1, 9+y1, 11+x1, 6+y1);
line(11+x1, 6+y1, 6+x1, 4+y1);
line(6+x1, 4+y1, 7+x1, 9+y1);
line(7+x1, 9+y1, 11+x1, 9+y1);
setcolor(YELLOW);
drawTer(15,367,20,383);
setcolor(RED);
drawDec(43,364,63,384);
setcolor(BROWN);
drawDly(8,395,20,395+18);
x1=38; y1=392;
setlinestyle(0, 1, 1);
setcolor(BLACK);
line(14+x1, 20+y1, 25+x1, 7+y1);
line(25+x1, 7+y1, 23+x1, 4+y1);
line(23+x1, 4+y1, 12+x1, 17+y1);
line(12+x1, 17+y1, 14+x1, 20+y1);
line(14+x1, 20+y1, 5+x1, 20+y1);
line(5+x1, 20+y1, 5+x1, 17+y1);
line(5+x1, 17+y1, 12+x1, 17+y1);
line(5+x1, 17+y1, 16+x1, 4+y1);
line(16+x1, 4+y1, 23+x1, 4+y1);
setfillstyle(1, DARKGRAY);
floodfill(14+x1, 18+y1, BLACK);
setfillstyle(1, WHITE);
floodfill(16+x1, 5+y1, BLACK);
setcolor(BLACK);
drawDio(8,426,24,442);
setcolor(BLUE);
drawMem(44,425,44+18,443);
return 0;
}
int colorPad()
{ int a;
setcolor(BLUE);
outtextxy(8,30,"COLOURS");

for(a=0;a<8;a++)
{ setcolor(DARKGRAY);
rectangle(xi+4,yi+40+a*30,xi+30,yi+40+26+a*30);
setfillstyle(1,2*a);
floodfill(xi+6,yi+42+a*30,DARKGRAY);
setcolor(DARKGRAY);
rectangle(xi+40,yi+40+a*30,xi+40+26,yi+25+40+a*30);
setfillstyle(1,2*a+1);
floodfill(xi+42,yi+42+a*30,DARKGRAY);
}
return 0;
}
int drawPad()
{ setcolor(WHITE);
rectangle(xi+80,yi+25,xl-4,yl-4);
return 0;
}

void inboard(int *x1,int *y1)
{
if(*x1>635) *x1=635;
if(*x1<80) *x1=80;
if(*y1>475) *y1=475;
if(*y1<=25) *y1=26;
}

int drawTer(int x1, int y1, int x2, int y2)
{
arc(x1,(y1+y2)/2,90,270,abs(y1-y2)/2);
arc(x2,(y1+y2)/2,270,90,abs(y1-y2)/2);
line(x1,y1,x2,y1);
line(x1,y2,x2,y2);
return 0;
}

int drawDec(int x1, int y1, int x2, int y2)
{ int rx,ry;
line((x1+x2)/2,y1,x2,(y1+y2)/2);
line(x2,(y1+y2)/2,(x1+x2)/2,y2);
line((x1+x2)/2,y2,x1,(y1+y2)/2);
line(x1,(y1+y2)/2,(x1+x2)/2,y1);
return 0;
}

int drawDly(int x1, int y1, int x2, int y2)
{
line(x1,y1,x1,y2);
arc(x2,(y1+y2)/2,270,90,abs(y1-y2)/2);
line(x1,y1,x2,y1);
line(x1,y2,x2,y2);
return 0;
}
int drawDio(int x1, int y1, int x2, int y2)
{ int r=x1+y1-x2-y2;
r=abs(r/12);
line(x1+r,y1,x2+r,y1);
line(x2+r,y1,x2-r,y2);
line(x2-r,y2,x1-r,y2);
line(x1-r,y2,x1+r,y1);
return 0;
}

int drawMem(int x1, int y1, int x2, int y2)
{ rectangle(x1,y1,x2,y2);
rectangle(x1,y1,x1+abs(x1-x2)/5,y1+abs(y1-y2)/5);
rectangle(x1+abs(x1-x2)/5,y1+abs(y1-y2)/5,x2,y2);
return 0;
}



int revColor(int col)
{ switch(col)
{case BLACK : return WHITE;
case BLUE : return LIGHTRED;
case GREEN : return RED;
case CYAN : return LIGHTMAGENTA;
case RED : return GREEN;
case MAGENTA : return LIGHTBLUE;
case BROWN : return LIGHTRED;
case LIGHTGRAY : return LIGHTMAGENTA;
case DARKGRAY : return YELLOW;
case LIGHTBLUE : return MAGENTA;
case LIGHTGREEN : return LIGHTCYAN;
case LIGHTCYAN : return LIGHTGREEN;
case LIGHTRED : return BROWN;
case LIGHTMAGENTA : return LIGHTGRAY;
case YELLOW : return DARKGRAY;
case WHITE : return BLACK;
}
return 0;
}
int getmsg(int x1, int y1){
if((x1>=4&&x1<=30)&&(y1>=40&&y1<=66)) return 0;
if((x1>=40&&x1<=66)&&(y1>=40&&y1<=66)) return 1;
if((x1>=4&&x1<=30)&&(y1>=70&&y1<=96)) return 2;
if((x1>=40&&x1<=66)&&(y1>=70&&y1<=96)) return 3;
if((x1>=4&&x1<=30)&&(y1>=100&&y1<=126)) return 4;
if((x1>=40&&x1<=66)&&(y1>=100&&y1<=126))return 5;
if((x1>=4&&x1<=30)&&(y1>=130&&y1<=156)) return 6;
if((x1>=40&&x1<=66)&&(y1>=130&&y1<=156))return 7;
if((x1>=4&&x1<=30)&&(y1>=160&&y1<=186)) return 8;
if((x1>=40&&x1<=66)&&(y1>=160&&y1<=186))return 9;
if((x1>=4&&x1<=30)&&(y1>=190&&y1<=216)) return 10;
if((x1>=40&&x1<=66)&&(y1>=190&&y1<=216))return 11;
if((x1>=4&&x1<=30)&&(y1>=220&&y1<=246)) return 12;
if((x1>=40&&x1<=66)&&(y1>=220&&y1<=246))return 13;
if((x1>=4&&x1<=30)&&(y1>=250&&y1<=276)) return 14;
if((x1>=40&&x1<=66)&&(y1>=250&&y1<=276))return 15;
//Search For Tools
if((x1>=4&&x1<=30)&&(y1>=300&&y1<=326)) return 21;
if((x1>=40&&x1<=66)&&(y1>=300&&y1<=326))return 22;
if((x1>=4&&x1<=30)&&(y1>=330&&y1<=356)) return 23;
if((x1>=40&&x1<=66)&&(y1>=330&&y1<=356))return 24;
if((x1>=4&&x1<=30)&&(y1>=360&&y1<=386)) return 25;
if((x1>=40&&x1<=66)&&(y1>=360&&y1<=386))return 26;
if((x1>=4&&x1<=30)&&(y1>=390&&y1<=416)) return 27;
if((x1>=40&&x1<=66)&&(y1>=390&&y1<=416))return 28;
if((x1>=4&&x1<=30)&&(y1>=420&&y1<=446)) return 29;
if((x1>=40&&x1<=66)&&(y1>=420&&y1<=446))return 30;
if((x1>=620&&x1<=634)&&(y1>=5&&y1<=19)) return 41;
if((x1>=80&&x1<=635)&&(y1>=25&&y1<=475))return 42;
return 43;
}

int draw(int type)
{ int x1,x2,y1,y2,button;
int i,j,temp;
switch(type)
{

case lin: getmousepos(&button,&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
inboard(&x1,&y1);
inboard(&x2,&y2);
line(x1,y1,x2,y2);
break;
case rec: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
inboard(&x2,&y2);
rectangle(x1,y1,x2,y2);
break;
case cir: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
inboard(&x2,&y2);
circle((x1+x2)/2,(y1+y2)/2,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/2);
break;
case pen: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
hidemouseptr();
while((button &1)!=0)
{ getmousepos(&button,&x2,&y2);
inboard(&x2,&y2);
line(x1,y1,x2,y2);
x1=x2; y1=y2;
}
showmouseptr();
break;
case ter: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
drawTer(x1,y1,x2,y2);
break;
case dec: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
drawDec(x1,y1,x2,y2);
break;
case dly: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
drawDly(x1,y1,x2,y2);
break;
case del: getmousepos(&button,&x1,&y1);
while((button &1)!=0)
{ getmousepos(&button,&x1,&y1);
x1-=5; y1-=5;
x2=x1+10; y2=y1+10;
inboard(&x1,&y1);
inboard(&x2,&y2);
for(i=y1;i<y2;i++)
{ for(j=x1;j<x2;j++)
putpixel(j,i,WHITE);
}
}
break;
case dio: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
drawDio(x1,y1,x2,y2);
break;
case mem: getmousepos(&button,&x1,&y1);
inboard(&x1,&y1);
while((button &1)!=0)
getmousepos(&button,&x2,&y2);
drawMem(x1,y1,x2,y2);
break;


}
return 0;
}
int main(void)
{ int gd=DETECT,gm,x1,y1,x2,i;
int x,y,button,msg,type;
//Initializing
initgraph(&gd,&gm,"c:\\tc\\bgi");
initmouse();
bar(xi,yi,xl,yl);
drawLayout();
showmouseptr();
//Setting Default Values
setcolor(1);
setfillstyle(1,1);
msg=21;
//Starting Program
while(1)
{ //Starting Windows Working in msg Style
getmousepos(&button,&x1,&y1);
while((button &1)!=1)
getmousepos(&button,&x1,&y1);

msg=getmsg(x1,y1);

if(msg>=0&&msg<=15) setcolor(msg);
else if(msg>=21&&msg<=30) type=msg;
else if(msg==42) draw(type);

else if(msg==41) return 0;

}
}#include<stdio.h>
#include<math.h>

long t(long i);
long leftRotate(long x, long c);
long s(long i);

#define A 0X01234567
#define B 0X89ABCDEF
#define C 0XFEDCBA98
#define D 0X76543210


long a,b,c,d;
char msg[512*32 ];
long len,nBlock,nPad,size,ptr;

long leftRotate(long x, long c)
{ return ((x<<c)|(x>>(32-c)));
}

long s(long i)
{ long arr[4][4]= { 7,12,17,22,
5, 9,14,20,
4,11,16,23,
6,10,15,21};
return arr[i/16][i%4];
}

long init()
{ system("cls");
len=strlen(msg);
ptr=len;
}

long step1()
{ nPad=len%64; //For bit: div by 512
nBlock=1+(len/64);

if(nPad>=56)
{ nBlock++;
nPad=120-nPad;
}
else nPad=64-nPad;

size=nBlock*64;
}

long step2()
{ union {long len; char lenByte[4];}temp;
long i=3;

temp.len=len;

msg[ptr++]=0x80; //Appending 1000 0000

while(ptr<size-4) //Appending 0b0 to all the bits in Empty Part
msg[ptr++]=0x00;

while(ptr<size) //Appending Length at Last
msg[ptr++]=temp.lenByte[i--];

msg[ptr]=0; //Appending a Last NULL
}


long step3()
{ a=A;
b=B;
c=C;
d=D;
}

long t(long i)
{ long arr[64]=
{ //List: 1 -> 1-16
0XD76AA478,0XE8C7B756,0X242070DB,0XC1BDCEEE,0XF57C0FAF,0X4787C62A,0XA8304613,0XFD469501,
0X698098D8,0X8B44F7AF,0XFFFF5BB1,0X895CD7BE,0X6B901122,0XFD987193,0XA679438E,0X49B40821,
//List: 2 -> 17-32
0XF61E2562,0XC040B340,0X265E5A51,0XE9B6C7AA,0XD62F105D,0X2441453,0XD8A1E681,0XE7D3FBC8,
0X21E1CDE6,0XC33707D6,0XF4D50D87,0X455A14ED,0XA9E3E905,0XFCEFA3F8,0X676F02D9,0X8D2A4C8A,
//List: 3 -> 33-48
0XFFFA3942,0X8771F681,0X6D9D6122,0XFDE5380C,0XA4BEEA44,0X4BDECFA9,0XF6BB4B60,0XBEBFBC70,
0X289B7EC6,0XEAA127FA,0XD4EF3085, 0X4881D05,0XD9D4D039,0XE6DB99E5,0X1FA27CF8,0XC4AC5665,
//List: 4 -> 49-64
0XF4292244,0X432AFF97,0XAB9423A7,0XFC93A039,0X655B59C3,0X8F0CCC92,0XFFEFF47D,0X85845DD1,
0X6FA87E4F,0XFE2CE6E0,0XA3014314,0X4E0811A1,0XF7537E82,0XBD3AF235,0X2AD7D2BB,0XEB86D391,
};
return arr[i];
}


//Main
long main(long argc, char* argv[])
{ long i,j,t1,t2,word,k,temp,*wPtr;
int *op;

printf("Please Enter the Message to find the Message Digest V 5: ");
gets(msg);

init();
step1();
step2();
step3();
for(i=0;i<nBlock;i++)
{ k=0;

for(j=0;j<64;j++)
{
if(0<=j && j<=15)
{ t1=(b&c)|((~b)&d);
t2=j;
} //f:t1,g:t2
else if(16<=j && j<=31)
{ t1=(d&b)|((~d)&c);
t2=(5*j+1)%16;
}
else if(32<=j && j<=47)
{ t1=b^c^d;
t2=(3*j+5)%16;
}
else if(48<=j && j<=63)
{ t1=c^(b|(~d));
t2=(7*j)%16;
}

wPtr=msg+(i*64+t2*4);
word=*wPtr;
t2=d; d=c; c=b;
b=b+leftRotate((a+t1+t(j)+word),s(j));
a=t2;
}
a+=A;
b+=B;
c+=C;
d+=D;
}


printf("\n\n8. MD5 Hash is: ");
op=&a;
printf("%X%X ",*op,*(op+1));
op=&b;
printf("%X%X ",*op,*(op+1));
op=&c;
printf("%X%X ",*op,*(op+1));
op=&d;
printf("%X%X ",*op,*(op+1));

//End of Program
getch();
return 0;
}

#include<stdio.h>
#include<math.h>

long t(long i);
long leftRotate(long x, long c);
long s(long i);

#define A 0X01234567
#define B 0X89ABCDEF
#define C 0XFEDCBA98
#define D 0X76543210


long a,b,c,d;
char msg[512*32 ];
long len,nBlock,nPad,size,ptr;

long leftRotate(long x, long c)
{ return ((x<<c)|(x>>(32-c)));
}

long s(long i)
{ long arr[4][4]= { 7,12,17,22,
5, 9,14,20,
4,11,16,23,
6,10,15,21};
return arr[i/16][i%4];
}

long init()
{ system("cls");
len=strlen(msg);
ptr=len;
}

long step1()
{ nPad=len%64; //For bit: div by 512
nBlock=1+(len/64);

if(nPad>=56)
{ nBlock++;
nPad=120-nPad;
}
else nPad=64-nPad;

size=nBlock*64;
}

long step2()
{ union {long len; char lenByte[4];}temp;
long i=3;

temp.len=len;

msg[ptr++]=0x80; //Appending 1000 0000

while(ptr<size-4) //Appending 0b0 to all the bits in Empty Part
msg[ptr++]=0x00;

while(ptr<size) //Appending Length at Last
msg[ptr++]=temp.lenByte[i--];

msg[ptr]=0; //Appending a Last NULL
}


long step3()
{ a=A;
b=B;
c=C;
d=D;
}

long t(long i)
{ long arr[64]=
{ //List: 1 -> 1-16
0XD76AA478,0XE8C7B756,0X242070DB,0XC1BDCEEE,0XF57C0FAF,0X4787C62A,0XA8304613,0XFD469501,
0X698098D8,0X8B44F7AF,0XFFFF5BB1,0X895CD7BE,0X6B901122,0XFD987193,0XA679438E,0X49B40821,
//List: 2 -> 17-32
0XF61E2562,0XC040B340,0X265E5A51,0XE9B6C7AA,0XD62F105D,0X2441453,0XD8A1E681,0XE7D3FBC8,
0X21E1CDE6,0XC33707D6,0XF4D50D87,0X455A14ED,0XA9E3E905,0XFCEFA3F8,0X676F02D9,0X8D2A4C8A,
//List: 3 -> 33-48
0XFFFA3942,0X8771F681,0X6D9D6122,0XFDE5380C,0XA4BEEA44,0X4BDECFA9,0XF6BB4B60,0XBEBFBC70,
0X289B7EC6,0XEAA127FA,0XD4EF3085, 0X4881D05,0XD9D4D039,0XE6DB99E5,0X1FA27CF8,0XC4AC5665,
//List: 4 -> 49-64
0XF4292244,0X432AFF97,0XAB9423A7,0XFC93A039,0X655B59C3,0X8F0CCC92,0XFFEFF47D,0X85845DD1,
0X6FA87E4F,0XFE2CE6E0,0XA3014314,0X4E0811A1,0XF7537E82,0XBD3AF235,0X2AD7D2BB,0XEB86D391,
};
return arr[i];
}


//Main
long main(long argc, char* argv[])
{ long i,j,t1,t2,word,k,temp,*wPtr;

printf("Please Enter the Message to find the Message Digest V 5: ");
gets(msg);

init();
step1();
step2();
step3();
for(i=0;i<nBlock;i++)
{ k=0;

for(j=0;j<64;j++)
{
if(0<=j && j<=15)
{ t1=(b&c)|((~b)&d);
t2=j;
} //f:t1,g:t2
else if(16<=j && j<=31)
{ t1=(d&b)|((~d)&c);
t2=(5*j+1)%16;
}
else if(32<=j && j<=47)
{ t1=b^c^d;
t2=(3*j+5)%16;
}
else if(48<=j && j<=63)
{ t1=c^(b|(~d));
t2=(7*j)%16;
}

wPtr=msg+(i*64+t2*4);
word=*wPtr;
t2=d; d=c; c=b;
b=b+leftRotate((a+t1+t(j)+word),s(j));
a=t2;
}
a+=A;
b+=B;
c+=C;
d+=D;
}


printf("\n\n8. MD5 Hash is: ");
printf("%X %X %X %X",a,b,c,d);

//End of Program
getch();
return 0;
}

Some of my frnd failed to run these pgm on TC as it was written on Win 32 pgm.. so I have Modified these acc to requirement..
TC
Linux

Reply of any prob.. till 4 AM

Enjoy the Life
Save Energy and Resources..

No comments:

Post a Comment