PDA

View Full Version : C/c++ Programmes



DATA
11-30-2001, 04:51 AM
hi,
May be we can make this thread for posting interesting,funny and
usefull c/c++ code.
Here is 1 below.
It actually write protects ur hard disk.

Well,one thing if any thing goes wrong with the programme dont
blame me for posting buggy code.
In most cases a reboot would set things right.

/*U cant quite compile the programme under c/c++
u'll have to
c:\>tcc -Emasm.exe protect.c
to get the .exe file
u'LL NEED tcc as well as masm to acheive that.
There is some asm code that u'll need masm
run the exe file or put it in ur autoexec.bat
u 'll be able to see the tsr in memory using the utility called MSD.exe
Only to be used under Ms-dos,other wise u may get some thing unexpected,if u dont mind a reeboot u can try it under windows as well.

If u have to remove this tsr programme frm memory,u ll need to write a
programme to do so or TERMINATE it from under windows
*/


#pragma inline
#include<dos.h>

struct INTERRUPT
{
unsigned bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
};


void interrupt(*prev)();
void interrupt our(struct INTERRUPT);

main()
{
prev=getvect(0x13);
setvect(0x13,our);
keep(0,1000);
}

void interrupt our(struct INTERRUPT r)
{
if(_AH==3||_AH==5||_AH==0x0b)
{
asm stc
asm pushf
asm pop.r.fl
return;
}

_ES=r.es;
_DX=r.dx;
_CX=r.cx;
_BX=r.bx;
_AX=r.ax;
(*prev)();
asm pushf
asm pop.r.fl
r.ax=_AX;
r.bx=_BX;
r.cx=_CX;
r.dx=_DX;
r.es=_ES;
}

DATA
12-01-2001, 03:26 AM
#include <dos.h>

union REGS i,o;
struct SREGS s;

int r,c,k;
char far *scr = (char far*)0xb8000000l,*buffer;
void writechar(char ch,int row,int col, int attb)
{
*(scr+row*160+col*2) = ch;
*(scr+row*160+col*2+1) = attb;
}

void writestring(char *str,int row,int col,int attb)
{

while(*str)
{
writechar(*str,row,col,attb);
str++;
col++;
}
}


void clrwin(int sr, int sc, int er, int ec, int attb)
{
i.h.ah = 6;
i.h.al = 0;
i.h.ch = sr;
i.h.cl = sc;
i.h.dh = er;
i.h.dl = ec;
i.h.bh = attb;

int86(0x10,&i,&i);
}


void savevideo(int sr, int sc, int er, int ec)
{
for(k=0,r=sr;r<=er;r++)
{
for(c=sc;c<=ec;c++)
{
buffer[k] = *(scr+r*160+c*2);
buffer[k+1] = *(scr+r*160+c*2+1);

k += 2;
}
}
}


void restorevideo(int sr, int sc, int er, int ec)
{
for(k=0,r=sr;r<=er;r++)
{
for(c=sc;c<=ec;c++)
{

*(scr+r*160+c*2) = buffer[k];
*(scr+r*160+c*2+1) = buffer[k+1];

k += 2;
}
}
}

DATA
12-01-2001, 03:28 AM
hi,

i have posted tsr.h,plz use it in ur file.
/*By Data*/
/*THIS IS PWORD SETTER */
/*place the exe in command.com or path in autoexec*/
/*Well this passwd setter has a few vulnerabilities
first autoexec.bat can be easily by passed.
However if u want to use this as a type of authetication for ur
valuble code,u can use this programme to do so,by setting a passwd.
However since the passwd i have used here is plain text,opening the
.exe code in a hex editor will reveal the password.So it is better
u use a crypo programme along with this.
Another alternative would be to use a linked list for each word of
ur passwd since linked lists dont store data sequentially in memory.

/*include tsr.h*/
#include <iostream.h>
#include<ctype.h>
#include "tsr.h"
#include<conio.h>
#include<stdio.h>
#include<dos.h>
# include <process.h>
#include <string.h>
int damn();
char *password;
char pass[]="ttt"; /*give password in the quotes*/
void main()
{
clrscr();
int i;
for( ;;)
{ gotoxy(25,12);
// textcolor(CYAN);
password=getpass("FIND THE GATE WAY TO BLISS:");


writestring("FROM :",1,23,10);
writestring(" THE ",2,28,12);
writestring("TIGER" ,2,36,14+128);
writestring(" WHO WANTS TO 'BYTE' U",2,41,12);
writestring("------------------------------------",3,28,12);



if(islower(* pass))
toupper(* pass);


if(strcmpi(pass,password)!=0)
{
gotoxy(25,13);
textattr(7+128);
writestring("SORRY ",13,25,12);
writestring("PAL",13,32,9+128);
writestring("TRY AGAIN:",13,36,12);

}
else
{
gotoxy(19,13);
textattr(7+128);
writestring("DEAR FRIEND,WELCOME TO MY WORLD...",13,20,14+128);

getch();
exit(0);

}
}//end for

}

DATA
12-01-2001, 03:58 AM
/*Here is a programme which i wrote a long while ago when i wondered
how brute force programmes get to check all combinations.
Be warned this programme is not exactly a brute force programme but
only written how to understand a brute force get to check all combinations.
It only checks all chareters upto 8 charecters.
u may modify it to check for alpha numeric,special charecters etc...
One last word,i dont think this programme is cleanly coded for
maximum effeciency,its only meant or fun.I would write one in .asm
rather*/

//BY Data...//
//Written for upto 8 alphabets in word//
//ran on turbo c++,ver 3.00,borland international inc.//
//U R FREE TO EDIT AND CHANGE THE PROGRAM//
//GOOD LUCK//
#include<time.h>
#include<iostream.h>
#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>

void main()
{

clrscr();
int i,j,k,l,m,n,o,p,count=0,tempcount,var,len,t1=0,t2=0,t3=0;
int flag1=0,flag2=0;
float avg=0.0;
char a,b,c,d,e,f,g,h;
char *s,input[8];
char array[1][8]; //check//
char temp[8];
char ch;


cout<<"ENTER THE LETTER :";

for(i=0;i<8;i++)
array[0][i]='\0';

cin>>input;
// for(i=0;i<8;i++)
// toupper(input[i]);
// for(i=0;i<8;i++)
//cout<<input[i];
len=strlen(input);

for(i=0;i<len;i++)
{

ch=toupper(input[i]);
input[i]=ch;
}


clock_t start, end; //FINDING EXECUTION TIME//
start = clock();



//COMMON CODE//

switch(len) //beg of switch//
{
case 1: for(i=65;i<92;i++)
{
count++;
a=toascii(i);

array[0][0]=a;

for(var=0,tempcount=0;var<1;var++,tempcount++)
temp[tempcount]=array[0][var];
flag1=flag2=0;
t1=0;

for(t1=0;t1<1;t1++)
if(input[t1]==temp[t1])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<1;var++)
cout<<array[0][var];


if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<1;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time was: %f\n", (end - start) / CLK_TCK);

if( (end-start)!=0 && CLK_TCK!=0 )
avg=count/( (end-start)/CLK_TCK );


cout<<"AVG: WORD CHECKS PER SECOND="<<avg;

getch();
exit(0);
}
//getch();
}//end for//



break;//code may have no effect//

case 2: for(i=65;i<92;i++)
for(j=65;j<92;j++)
{
count++;

a=toascii(i);
b=toascii(j);

array[0][0]=a;
array[0][1]=b;


for(var=0,tempcount=0;var<2;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=0;


for(t1=0;t1<2;t1++,t2++)
if(input[t1]==temp[t2])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<2;var++)
cout<<array[0][var];


if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<2;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

if( (end-start)!=0 && CLK_TCK!=0 )
avg=count/( (end-start)/CLK_TCK );

cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end for//


break;//watch//


case 3: for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
{
count++;

a=toascii(i);
b=toascii(j);
c=toascii(k);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;

for(var=0,tempcount=0;var<3;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=t3=0;

for(t1=0;t1<3;t1++,t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<3;var++)
cout<<array[0][var];


if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<3;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end for//

break;//watch//



case 4: for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
for(l=65;l<92;l++)
{
count++;

a=toascii(i);
b=toascii(j);
c=toascii(k);
d=toascii(l);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;
array[0][3]=d;

for(var=0,tempcount=0;var<4;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=t3=0;

for(t1=0;t1<4;t1++,t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<8;var++)
cout<<array[0][var];



if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<8;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;

getch();
exit(0);
}
//getch();
}//end for//
break;//watch//





case 5: for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
for(l=65;l<92;l++)
for(m=65;m<92;m++)
{
count++;

a=toascii(i);
b=toascii(j);
c=toascii(k);
d=toascii(l);
e=toascii(m);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;
array[0][3]=d;
array[0][4]=e;

for(var=0,tempcount=0;var<5;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=t3=0;

for(t1=0;t1<5;t1++,t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;


cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<8;var++)
cout<<array[0][var];



if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<8;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end of for//
break;//watch//

case 6:for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
for(l=65;l<92;l++)
for(m=65;m<92;m++)
for(n=65;n<92;n++)
{
count++;

a=toascii(i);
b=toascii(j);
c=toascii(k);
d=toascii(l);
e=toascii(m);
f=toascii(n);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;
array[0][3]=d;
array[0][4]=e;
array[0][5]=f;

for(var=0,tempcount=0;var<6;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=t3=0;

for(t1=0;t1<6;t1++,t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<6;var++)
cout<<array[0][var];

if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<6;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end for//
break;//watch//



case 7: for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
for(l=65;l<92;l++)
for(m=65;m<92;m++)
for(n=65;n<92;n++)
for(o=65;o<92;o++)
{

count++;

a=toascii(i);
b=toascii(j);
c=toascii(k);
d=toascii(l);
e=toascii(m);
f=toascii(n);
g=toascii(o);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;
array[0][3]=d;
array[0][4]=e;
array[0][5]=f;
array[0][6]=g;

for(var=0,tempcount=0;var<7;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t2=t3=0;

for(t2=0;t2<7;t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<7;var++)
cout<<array[0][var];

DATA
12-01-2001, 04:01 AM
if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<7;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n", (end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end for/

break;//watch//


case 8:for(i=65;i<92;i++)
for(j=65;j<92;j++)
for(k=65;k<92;k++)
for(l=65;l<92;l++)
for(m=65;m<92;m++)
for(n=65;n<92;n++)
for(o=65;o<92;o++)
for(p=65;p<92;p++)
{ count++;
a=toascii(i);
b=toascii(j);
c=toascii(k);
d=toascii(l);
e=toascii(m);
f=toascii(n);
g=toascii(o);
h=toascii(p);

array[0][0]=a;
array[0][1]=b;
array[0][2]=c;
array[0][3]=d;
array[0][4]=e;
array[0][5]=f;
array[0][6]=g;
array[0][7]=h;

for(var=0,tempcount=0;var<8;var++,tempcount++)
temp[tempcount]=array[0][var];

flag1=flag2=0;
t1=t2=t3=0;

for(t1=0;t1<8;t1++,t2++,t3++)
if(input[t2]==temp[t3])
flag1=1;
else
flag2=1;

cout<<endl<<"\t\t\t\t\t\t\t";

for(var=0;var<8;var++)
cout<<array[0][var];

if(flag1==1&&flag2!=1)
{
cout<<"\nSUCCESS\n";

for(var=0;var<8;var++)
cout<<array[0][var];

end = clock();
printf("\nThe time in seconds was: %f\n",(end - start) / CLK_TCK);

avg=count/( (end-start)/CLK_TCK );
cout<<"AVG: WORD CHECKS PER SECOND="<<avg;


getch();
exit(0);
}
//getch();
}//end for//
break;//watch//

default:cout<<endl<<"PROGRAMME WRITTEN ONLY FOR UPTO 8 ALPHABETS...";
getch();


}//end of switch//


}//end main//