# include <stdio.h>
# include <process.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>
# include <conio.h>
# include <fcntl.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <dir.h>
# include <dos.h>
# include <string.h>
# include <math.h>
# define ESC 27
#define BLANK 101
#define ENTER 102
#define TS 103
/* various menu definitions */
/* character following `^' is a hot key */
char *mainmenu[] = {
"^File",
"^Help",
"^Exit"
} ;
char *filemenu[] = {
"^Copy a file Ctrl+C" ,
"^Delete a file Ctrl+D ",
"^Encrypt a text file Ctrl+E",
"decr^Ypt a coded file Ctrl+Y",
"d^Isplay a text file Ctrl+I",
"^Return"
} ;
char *helpmenu[] = {
"^About application Ctrl+A ",
"help to^Pics Ctrl+P",
"^Return"
} ;
char *exitmenu[] = {
"^Return",
"e^Xit Alt+X"
} ;
/* help messages for different menu items and other frequently required messages */
char *messages[] = {
"Please enter source file name !",
"Enter file name with extension!" ,
"Enter file name with appropriate extension!",
" Press any key to continue... ",
" Insufficient space! Press any key... " ,
"Memory Allocation Error! Press any key...",
" Press Y for Yes and N for No... ",
} ;
/* buffer in which files are loaded and manipulated */
char *buf ;
unsigned maxsize ;
int ascii, scan;
int ctrl_c_flag = 0 ;
char far *vid_mem ;
char far *ins = ( char far * ) 0x417 ;
main ( int argc, char *argv[] )
{
int flag ;
/*Store base address of VDU memory & set appropriate video mode*/
#ifdef MA
{ /*Store base address for MA*/
vid_mem = ( char far * ) 0xb0000000L ;
setmode ( 3 ) ;
}
#else
{
/*Store base address for other display device*/
vid_mem = ( char far * ) 0xb8000000L ;
setmode ( 7 ) ;
}
#endif
size ( 32, 0 ) ; /*hides the cursor*/
logo(); /* creates opening screen*/
size ( 32, 0 ) ;
pswscreen(); /* creates password screen*/
size ( 32, 0 ) ;
workscreen() ; /* display working screen */
displaymenuh ( mainmenu, 3 ) ; /* display the main menu */
size ( 32, 0 ) ; /*hide the cursor*/
while ( 1 )
{
getkey() ; /* receive key */
/* if special key has been hit */
if ( ascii == 0 )
{
/* check which special key */
switch ( scan )
{
case 33 : /* Alt - F */
/* highlight the menu item */
writestring ( mainmenu[0], 0, 2, 15 ) ;
/* call file services */
fserver() ;
/* make highlighted item normal */
writestring ( mainmenu[0], 0, 2, 112 ) ;
break ;
case 35 : /* Alt-H key */
/* highlight the menu item */
writestring ( mainmenu[1], 0, 14, 15 ) ;
/* call help services */
hserver() ;
/* make highlighted item normal */
writestring ( mainmenu[1], 0, 14, 112 ) ; break ;
case 18: /* Alt-E*/
/* highlight the menu item */
writestring ( mainmenu[2], 0, 26, 15 ) ;
/* call help services */
eserver();
/* make highlighted item normal */
writestring ( mainmenu[2], 0, 26, 112 ) ;
break;
case 45 : /* Alt - X */
/* exit the application */
size ( 6, 7 ) ;
clrscr() ; // to clear the dos screen
exit(1);
break;
case 68 : /* F10 key */
mm_server() ;/* call mainmenu */
break ;
case 59 : /*F1 key*/
helptopic();
break;
}
}//end of if
else
{
switch(ascii)
{
case 3 : /* CTRL - C*/
copyfile();
break;
case 4 : /*CTRL-D*/
deletefile();
break;
case 5 : /*CTRL-E*/
encryptfile();
break;
case 25 : /*CTRL-Y*/
decryptfile();
break;
case 9 : /*CTRL-I*/
displayfile();
break;
case 1 : /*CTRL-A*/
about();
break;
case 16 : /*CTRL-P*/
helptopic();
break;
}
}//end of else
}
}
//////////////////////////////////////////////////////////
/* creates working screen */
workscreen()
{
gotoxy(80,25);
size ( 32, 0 ) ; /*hide the cursor*/
/* draw filled box on screen */
menubox ( 0, 0, 24, 81, 27);
/* draw a box around editing portion of screen */
drawbox ( 1, 0, 23, 79, 27) ;
status_line();
}
//////////////////////////////////////////////////////////
/* displays certain special keys and their significance */
status_line()
{
writestring ( " ", 24, 0, 112 ) ;
writestring ( " ^A^l^t-^F File ^A^l^t-^H Help ^A^l^t^-^X Exit ^F^1 Help Topics ", 24, 8, 112 ) ;
}
//////////////////////////////////////////////////////////
/* checks value to the raed char*/
int check(int value)
{
int new_val;
if(value==BLANK)
new_val=0;
else if(value==ENTER)
new_val=13;
else if(value==TS)
new_val=26;
else
new_val=value;
return(new_val);
}
//////////////////////////////////////////////////////////
/* assign value to the raed char*/
int assign(int value)
{
int new_val;
if(value==0)
new_val=BLANK;
else if(value==13)
new_val=ENTER;
else if(value==26)
new_val=TS;
else
new_val=value;
return(new_val);
}
//////////////////////////////////////////////////////////
/* writes a character in specified attribute */
writechar ( int r, int c, char ch, int attb )
{
char far *v ;
v = vid_mem + r * 160 + c * 2 ; /* calculate address corresponding to row r and column c */
*v = ch ; /* store ascii value of character */
v++ ;
*v = attb ; /* store attribute of character */
}
//////////////////////////////////////////////////////////
/* writes a string in specified attribute */
writestring ( char *s, int r, int c, int attb )
{
while ( *s != '\0' )
{
/* if next character is the hot key of menu item */
if ( *s == '^' )
{
s++ ;
/* if hot key of highlighted bar */
if ( attb == 15 )
writechar ( r, c, *s, 15 ) ;
else
writechar ( r, c, *s, 113 ) ;
}
else
{
writechar ( r, c, *s, attb ) ; /* normal character */
}
c++ ;
s++ ;
}
}
//////////////////////////////////////////////////////////
/* saves screen contents into allocated memory */
savevideo ( int sr, int sc, int er, int ec, char *buffer )
{
char far *v ;
int i, j ;
for ( i = sr ; i <= er ; i++ )
{
for ( j = sc ; j <= ec ; j++ )
{
v = vid_mem + i * 160 + j * 2 ;
*buffer = *v ; /* store character */
v++ ;
buffer++ ;
*buffer = *v ; /* store attribute */
buffer++ ;
}
}
}
/////////////////////////////////////////////////////////
/* restores screen contents from allocated memory */
restorevideo ( int sr, int sc, int er, int ec, char *buffer )
{
char far *v ;
int i, j ;
for ( i = sr ; i <= er ; i++ )
{
for ( j = sc ; j <= ec ; j++ )
{
v = vid_mem + i * 160 + j * 2 ;
*v = *buffer ; /* restore character */
v++ ;
buffer++ ;
*v = *buffer ; /* restore attribute */
buffer++ ;
}
}
}
//////////////////////////////////////////////////////////
/* displays filled box*/
menubox ( int sr, int sc, int er, int ec, char fil)
{
int i, j ;
for ( i = sr ; i < er ; i++ )
for ( j = sc ; j < ( ec - 1 ) ; j++ )
writechar ( i, j, ' ', fil ) ;
}
//////////////////////////////////////////////////////////
/* draws a double-lined box */
drawbox ( int sr, int sc, int er, int ec, int attr )
{
int i ;
/* draw horizontal lines */
for ( i = sc + 1 ; i < ec ; i++ )
{
writechar ( sr, i , 205, attr ) ;
writechar ( er, i, 205, attr ) ;
}
/* draw vertical lines */
for ( i = sr + 1 ; i < er ; i++ )
{
writechar ( i, sc, 186, attr ) ;
writechar ( i, ec, 186, attr ) ;
}
/* display corner characters */
writechar ( sr, sc, 201, attr ) ;
writechar ( sr, ec, 187, attr ) ;
writechar ( er, sc, 200, attr ) ;
writechar ( er, ec, 188, attr ) ;
}
//////////////////////////////////////////////////////////
/* displays or hides cursor */
size ( int ssl, int esl )
{
union REGS i, o ;
i.h.ah = 1 ; /* service number */
i.h.ch = ssl ; /* starting scan line */
i.h.cl = esl ; /* ending scan line */
i.h.bh = 0 ; /* video page number */
/* issue interrupt for changing the size of the cursor */
int86 ( 16, &i, &o ) ;
}
//////////////////////////////////////////////////////////
/* gets ascii and scan code of key pressed */
getkey()
{
union REGS i, o ;
i.h.ah = 0 ; /* service number */
/* issue interrupt */
int86 ( 22, &i, &o ) ;
ascii = o.h.al ;
scan = o.h.ah ;
}
//////////////////////////////////////////////////////////
/* pops up a menu vertically */
popupmenuv ( char **menu, int count, int sr, int sc, char *hotkeys)
{
int er, i, ec, l, len = 0, area, choice ;
char *p ;
size ( 32, 0 ) ; /* hide cursor */
/* calculate ending row for menu */
er = sr + count + 2 ;
/* find longest menu item */
for ( i = 0 ; i < count ; i++ )
{
l = strlen ( menu[i] ) ;
if ( l > len )
len = l ;
}
/* calculate ending column for menu */
ec = sc + len + 5 ;
/* calculate area required to save screen contents where menu is to be popped up */
area = ( er - sr + 1 ) * ( ec - sc + 1 ) * 2 ;
p = malloc ( area ) ; /* allocate memory */
/* if allocation fails */
if ( p == NULL )
error_exit() ;
/* save screen contents into allocated memory */
savevideo ( sr, sc, er, ec, p ) ;
/* draw filled box with shadow */
menubox ( sr, sc + 1, er, ec, 112);
/* draw a double lined box */
drawbox ( sr, sc + 1, er - 1, ec - 2, 112 ) ;
/* display the menu in the filled box */
displaymenuv ( menu, count, sr + 1, sc + 3 ) ;
/* receive user's choice */
choice = getresponsev ( menu, hotkeys, sr, sc + 2, count);
/* restore original screen contents */
restorevideo ( sr, sc, er, ec, p ) ;
/* free allocated memory */
free ( p ) ;
size ( 5, 7 ) ; /* set cursor to normal size */
return ( choice ) ;
}
//////////////////////////////////////////////////////////
/* displays menu vertically */
displaymenuv ( char **menu, int count, int sr, int sc )
{
int i ;
for ( i = 0 ; i < count ; i++ )
{
writestring ( menu[i], sr, sc, 112 ) ;
sr++ ;
}
}
//////////////////////////////////////////////////////////
/* receives user's choice for the vertical menu displayed */
getresponsev ( char **menu, char *hotkeys, int sr, int sc, int count)
{
int choice = 1, len, hotkeychoice ;
/* calculate number of hot keys for the menu */
len = strlen ( hotkeys ) ;
/* highlight the first menu item */
writestring ( menu[choice - 1], sr + choice, sc + 1, 15 ) ;
while ( 1 )
{
/* receive key */
getkey() ;
/* if special key is hit */
if ( ascii == 0 )
{
switch ( scan )
{
case 80 : /* down arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], sr + choice, sc + 1, 112 ) ;
choice++ ;
break ;
case 72 : /* up arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], sr + choice, sc + 1, 112 ) ;
choice-- ;
break ;
case 77 : /* right arrow key */
return ( 77 ) ;
case 75 : /* left arrow key */
return ( 75 ) ;
}
/* if highlighted bar is on first item and up arrow key is hit */
if ( choice == 0 )
choice = count ;
/* if highlighted bar is on last item and down arrow key is hit */
if ( choice > count )
choice = 1 ;
/* highlight the appropriate menu item */
writestring ( menu[choice - 1], sr + choice, sc + 1, 15 ) ;
}
else
{
if ( ascii == 13 ) /* Enter key */
return ( choice ) ;
if ( ascii == ESC )
{
displaymenuh ( mainmenu, 3 ) ;
return ( ESC ) ;
}
hotkeychoice = 1 ;
ascii = toupper ( ascii ) ;
/* check whether hot key has been pressed */
while ( *hotkeys != '\0' )
{
if ( *hotkeys == ascii )
return ( hotkeychoice ) ;
else
{
hotkeys++ ;
hotkeychoice++ ;
}
}
/* reset variable to point to the first hot key character */
hotkeys = hotkeys - len ;
}
}
}
//////////////////////////////////////////////////////////
/* displays menu horizontally */
displaymenuh ( char **menu, int count )
{
int col = 2, i ;
size ( 32, 0 ) ;
menubox ( 0, 0, 0, 79, 112);
for ( i = 0 ; i < count ; i++ )
{
writestring ( " ", 0, col-2, 112 ) ;
writestring ( menu[i], 0, col, 112 ) ;
col = col + ( strlen ( menu[i] ) ) + 7;
}
size ( 5, 7 ) ;
}
//////////////////////////////////////////////////////////
/* receives user's choice for the horizontal menu displayed */
getresponseh ( char **menu, char *hotkeys, int count )
{
int choice = 1, hotkeychoice, len, col ;
size ( 32, 0 ) ;
col = 2 ;
/* calculate number of hot keys for the menu */
len = strlen ( hotkeys ) ;
/* highlight the first menu item */
writestring ( menu[choice - 1], 0, col, 15 ) ;
while ( 1 )
{
/* receive key */
getkey() ;
/* if special key is hit */
if ( ascii == 0 )
{
switch ( scan )
{
case 77 : /* right arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], 0, col, 112 ) ;
col += strlen ( menu[choice - 1] ) + 7 ;
choice++ ;
break ;
case 75 : /* left arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], 0, col, 112 ) ;
col -= ( strlen ( menu[choice - 2] ) + 7 ) ;
choice-- ;
break ;
}
/* if highlighted bar is on the first item and left arrow key is hit */
if ( choice == 0 )
{
choice = count ;
col = 65 ;
}
/* if highlghted bar is on the last item and right arrow key is hit */
if ( choice > count )
{
choice = 1 ;
col = 2 ;
}
/* highlight the appropriate menu item */
writestring ( menu[choice - 1], 0, col, 15 ) ;
}
else
{
if ( ascii == 13 ) /* Enter key */
{
size ( 5, 7 ) ;
return ( choice ) ;
}
if ( ascii == ESC ) /* Esc key */
{
/* make highlighted item normal */
writestring ( menu[choice - 1], 0, col, 112 ) ;
size ( 5, 7 ) ;
return ( ESC ) ;
}
hotkeychoice = 1 ;
ascii = toupper ( ascii ) ;
/* check whether hot key has been pressed */
while ( *hotkeys != '\0' )
{
if ( *hotkeys == ascii )
{
size ( 5, 7 ) ;
return ( hotkeychoice ) ;
}
else
{
hotkeys++ ;
hotkeychoice++ ;
}
}
/* reset variable to point to the first hot key character */
hotkeys = hotkeys - len ;
}
}
}
//////////////////////////////////////////////////////////
/* displays error message and terminates execution */
error_exit()
{
// writestring ( "Memory Allocation Error! Press any key...", 22, 14, 112 ) ;
writestring ( messages[5], 22, 14, 112 ) ;
fflush ( stdin ) ;
getch() ;
exit ( 2 ) ;
}
//////////////////////////////////////////////////////////
/* displays Main Menu, receives choice and branches control to appropriate function */
mm_server()
{
int mchoice, esc_flag ;
while ( 1 )
{
displaymenuh ( mainmenu, 3 ) ;
mchoice = getresponseh ( mainmenu, "FPX",3);
switch ( mchoice )
{
case 1 :
esc_flag = fserver() ;
break ;
case 2 :
esc_flag = hserver() ;
break ;
case 3 :
esc_flag = eserver() ;
break ;
case ESC : /* if Esc key is hit when in horizontal main menu */
esc_flag = ESC ;
}
/* if Esc key has been hit in vertical or horizontal menu */
if ( esc_flag == ESC )
return ( esc_flag ) ;
}
}
//////////////////////////////////////////////////////////
/* displays file menu, receives choice and branches control to appropriate function */
fserver()
{
int cchoice, esc_flag = 0 ;
/* pop up file menu */
cchoice = popupmenuv ( filemenu, 6, 1, 0, "CDEYDT");
/* call appropriate functions */
switch ( cchoice )
{
case 1 :
copyfile() ;
break ;
case 2 :
deletefile() ;
break ;
case 3 :
encryptfile() ;
break ;
case 4 :
decryptfile() ;
break ;
case 5 :
displayfile() ;
break ;
case 6 :
/* call main menu services */
esc_flag = mm_server() ;
break ;
case 75 : /* left arrow key */
/* make the `File' menu item normal */
writestring ( mainmenu[0], 0, 2, 112 ) ;
/* highlight the `Exit' menu item */
writestring ( mainmenu[2], 0, 26, 15 ) ;
/* call exit services */
esc_flag = eserver() ;
/* make the `Exit' menu item normal */
writestring ( mainmenu[2], 0, 26, 112 ) ;
break ;
case 77 : /* right arrow key */
/* make the `File' menu item normal */
writestring ( mainmenu[0], 0, 2, 112 ) ;
/* highlight the `Help' menu item */
writestring ( mainmenu[1], 0, 14, 15 ) ;
/* call help services */
esc_flag = hserver() ;
/* make the `Help' menu item normal */
writestring ( mainmenu[1], 0, 14, 112 ) ;
break ;
case ESC :
esc_flag = ESC ;
}
return ( esc_flag ) ;
}
//////////////////////////////////////////////////////////
/* displays Help menu, receives choice and branches control to appropriate function */
hserver()
{
int fchoice, flag, esc_flag = 0 ;
char fname[30] ;
fchoice = popupmenuv ( helpmenu, 3, 1, 14, "APT");
switch ( fchoice )
{
case 1 :
about() ;
break ;
case 2 :
helptopic();
break;
case 3 :
/* call main menu services */
esc_flag = mm_server() ;
break ;
case 75 : /* left arrow key */
/* display file menu */
writestring ( mainmenu[1], 0, 14, 112) ;
writestring ( mainmenu[0], 0, 2, 15 ) ;
esc_flag = fserver() ;
writestring ( mainmenu[0], 0, 2, 112 ) ;
break ;
case 77 : /* right arrow key */
/* display Exit menu */
writestring ( mainmenu[1], 0, 14, 112 ) ;
writestring ( mainmenu[2], 0, 26, 15 ) ;
esc_flag = eserver() ;
writestring ( mainmenu[2], 0, 26, 112 ) ;
break ;
case ESC :
esc_flag = ESC ;
}
return ( esc_flag ) ;
}
//////////////////////////////////////////////////////////
/* displays Exit menu, receives choice and branches control to appropriate function */
eserver()
{
int fchoice, esc_flag ;
fchoice = popupmenuv ( exitmenu, 2, 1, 26, "ET");
switch ( fchoice )
{
case 1 : /* call main menu services */
esc_flag = mm_server() ;
break;
case 2 : /* exit the application*/
size ( 6, 7 ) ;
clrscr() ;
exit ( 0 ) ;
break ;
case 75 : /* left arrow key */
/* display Help menu */
writestring ( mainmenu[2], 0, 26, 112 ) ;
writestring ( mainmenu[1], 0, 14, 15 ) ;
esc_flag = hserver() ;
writestring ( mainmenu[1], 0, 14, 112 ) ;
break ;
case 77 : /* right arrow key */
/* display file menu */
writestring ( mainmenu[2], 0, 26, 112 ) ;
writestring ( mainmenu[0], 0, 2, 15 ) ;
esc_flag = fserver() ;
writestring ( mainmenu[0], 0, 2, 112 ) ;
break ;
case ESC :
esc_flag = ESC ;
}
return ( esc_flag ) ;
}
//////////////////////////////////////////////////////////
copyfile()
{
char sfile[20],tfile[20],buffer[512],*p;
int areareqd, inhandle,outhandle,bytes,flag,k,i,j;
areareqd = ( 23 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2;
p=malloc(areareqd);
if ( p == NULL)
{
printf("\a");
writestring ( messages[4],22,11,32 );
getch();
return;
}
savevideo (5,5,23,70,p);
menubox(6,5,13,70,32);
writestring(" File copy service ",22,11,164);
writestring ( "Enter source file name : ",7,8,32);
size( 6,7 ); //display cursor
gotoxy( 33,8 );
getkey();
if (ascii==ESC)
{
// restore original screen contents
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
gets (sfile);
size ( 32, 0 ) ; /* hide cursor */
k=strlen( sfile );
// to make sure that file name is entered with extension
i=0;
while(sfile[i]!='\0')
{
if(sfile[i]!='.')
j=0;
if(sfile[i]=='.')
{
j=1;
break;
}
i++;
}
if(j==0)
{
printf("\a");
writestring ( messages[1], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free(p);
return ;
}
/* open source file in low level binary mode for reading */
inhandle = open ( sfile, O_RDONLY | O_BINARY ) ;
/* if unable to open file */
if ( inhandle < 0 )
{
printf("\a");
writestring ( "Source file not found!", 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
return ;
}
writestring ( "Enter target file name : ", 9, 8, 32 ) ;
size ( 6, 7 ) ;
gotoxy ( 33, 10 ) ;
getkey();
if (ascii==ESC)
{
//close file and restore original screen contents
close ( inhandle );
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
gets ( tfile ) ;
size ( 32, 0 ) ;
/* open target file in low level binary mode for writing */
outhandle = open ( tfile,O_WRONLY | O_BINARY,S_IWRITE );
// check whether the file already exists
if(outhandle > 0)
{
menubox(13,5,16,70,32);
writestring ( "Target file already exists! Do you want to replace? ",11,8,32);
// display Yes button
menubox ( 13, 27, 14, 35, 110);
writestring ( "Yes", 13, 28, 110 ) ;
// display No button
menubox ( 13, 37, 14, 44, 110);
writestring ( "No", 13, 39, 110 ) ;
printf("\a");
writestring ( messages[6], 22,9, 110) ;
getkey();
if( (ascii!='y')&&(ascii!='Y')&&(ascii!='n')&&(ascii!='N') )
{
printf("\a");
getkey();
}
if( (ascii=='y') || (ascii=='Y') )
{
for ( i = 13 ; i <= 16 ; i++ )
{
for ( j = 5 ; j <= 70 ; j++ )
writechar ( i, j, ' ', 27) ;
writechar ( i, j, ' ', 27 ) ;
}
while (( bytes = read (inhandle,buffer,512)) > 0 )
{
flag = write( outhandle,buffer,bytes );
if( flag == -1)
break;
}
if(flag == -1)
{
printf("\a");
writestring ( "Unable to copy file!",11,8,32);
}
else
writestring ( " ",11,8,32);
writestring ( "File has been sucessfully copied! ",11,7,32);
writestring ( messages[3],22,9,164);
getch();
//close files and restore original screen contents
close ( inhandle );
close ( outhandle );
restorevideo(5,5,23,70,p);
free ( p );
}//end of if(ascii=='Y'.....)
if( (ascii=='n') || (ascii=='N') )
{
//close files and restore original screen contents
close ( inhandle );
close ( outhandle );
restorevideo(5,5,23,70,p);
free ( p );
return;
}
}// end of if(outhandle > 0 )
else
{
outhandle = open ( tfile,O_WRONLY | O_CREAT | O_BINARY,S_IWRITE );
/*read chunks of 512 bytes from source file and write to target file till there are bytes to read*/
while (( bytes = read (inhandle,buffer,512)) > 0 )
{
flag = write( outhandle,buffer,bytes );
if( flag == -1)
break;
}
if(flag == -1)
{
printf("\a");
writestring ( "Unable to copy file!",11,8,32);
}
else
writestring ( "File has been sucessfully copied!",11,8,32);
writestring ( messages[3],22,14,164);
getch();
/*close files and restore original screen contents*/
close ( inhandle );
close ( outhandle );
restorevideo(5,5,23,70,p);
free ( p );
workscreen();
displaymenuh(mainmenu,3);
size(32,0);
}
}// end of function copyfile()
//////////////////////////////////////////////////////////
/*To delete an existing file*/
deletefile()
{
union REGS ii, oo ;
int areareqd ;
char filename[20], *p ;
areareqd = ( 23 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
printf("\a");
writestring ( messages[4],22,11,32 );
getch() ;
return ;
}
savevideo ( 5, 5, 23, 70, p ) ;
menubox ( 6, 5, 11, 65, 32);
writestring ( " File delete service " , 22, 11, 164 ) ;
writestring ( "Enter name of file to be deleted:", 7, 8, 32 ) ;
size ( 6, 7 ) ;
gotoxy ( 43, 8 ) ;
getkey();
if (ascii==ESC)
{
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
gets ( filename ) ;
size ( 32, 0 ) ;
/* issue interrupt for deleting file */
ii.h.ah = 65 ; /* dos service number */
ii.x.dx = ( unsigned int ) filename ; /* store base address */
intdos ( &ii, &oo ) ;
/* check if successful in deleting file */
if ( oo.x.cflag == 0 )
writestring ( "File is successfully deleted!", 9, 8, 32 ) ;
else
{
switch ( oo.x.ax )
{
case 2 :
{
printf("\a");
writestring ( "File not found!", 9, 8, 32 ) ;
break ;
}
case 3 :
{
printf("\a");
writestring ( "Invalid path!", 9, 8, 32 ) ;
break ;
}
case 5 :
{
printf("\a");
writestring ( "Access denied!", 9, 8, 32 ) ;
break ;
}
case 0x11 :
{
printf("\a");
writestring ( "Invalid drive name!", 9, 8, 32 ) ;
break ;
}
default :
{
printf("\a");
writestring ( "Improper request!", 9, 8, 32 ) ;
}
}
}
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
workscreen();
displaymenuh(mainmenu,3);
size(32,0);
}
//////////////////////////////////////////////////////////
/* To encrypt a text file*/
encryptfile()
{
char *buf,*ptr;
char sfile[20], tfile[20], *p, s1[5],buffer[3],value,output[10];
FILE *fps , *fpt ;
int areareqd, flag ,count, ch,len,bytes;
int a,k,i,j,z,w,b[100],mod;
unsigned long int n,c,out,e;
buf = malloc(1);
areareqd = ( 23 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
printf("\a");
writestring ( messages[4], 22, 11, 32 );
getch() ;
return ;
}
savevideo ( 5, 5, 23, 70, p ) ;
menubox ( 6, 5, 13, 60, 32);
writestring ( " File coding service ", 22, 11, 164 ) ;
writestring ( "Enter source file name:", 7, 8, 32 ) ;
size ( 6, 7 ) ;
gotoxy ( 33, 8 ) ;
getkey();
if (ascii==ESC)
{
//restore original screen contents
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
gets ( sfile ) ;
size ( 32, 0 ) ;
ptr=strstr(sfile,".srs");
if (ptr!=NULL)
{
printf("\a");
writestring("File is already encrypted !",9,8,32);
writestring ( messages[3], 22, 14, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
return ;
}
k=strlen( sfile );
// to make sure that file name is entered with extension
i=0;
while(sfile[i]!='\0')
{
if(sfile[i]!='.')
j=0;
if(sfile[i]=='.')
{
j=1;
break;
}
i++;
}
if(j==0)
{
printf("\a");
writestring ( messages[1], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free(p);
size(32,0);
return ;
}
else
{
/* open source file */
fps = open ( sfile, O_RDONLY | O_BINARY, S_IREAD ) ;
if ( fps == -1 )
{
printf("\a");
writestring ( "Source file not found!",9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free(p);
return ;
}
writestring ( "Enter the keys of enryption n : ", 9, 8, 32 ) ;
writestring ( " e : ", 10, 8, 32 ) ;
size ( 6, 7 );
gotoxy ( 47, 10 );
getkey();
if (ascii==ESC)
{
//restore original screen contents
close ( sfile );
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
scanf("%lu", &n);
gotoxy ( 47, 11 );
scanf("%lu", &e);
size ( 32, 0 ) ;
k=strlen(sfile);
/* // to make sure that file name is entered or not
if( k <= 0 )
{
printf("\a");
writestring ( messages[0], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
return ;
} */
for(i=0;i<k;i++)
{
if(sfile[i]=='.')
{
j=1;
z=k-2-i;
for(a=0;a<=z;a++)
{
s1[a]=sfile[i+1];
i++;
}
}
}
s1[a+1]='\0';
for(i=0;i<k;i++)
{
if( sfile[i]=='.' )
{
sfile[i+1]='s';
sfile[i+2]='r';
sfile[i+3]='s';
sfile[i+4]='\0';
break;
}
}
// to make filename of encrypted file as sourcefile.srs
strcpy(tfile,sfile);
/* open target file */
fpt = open ( tfile,O_CREAT |O_TRUNC| O_WRONLY | O_BINARY,S_IREAD | S_IWRITE);
/*RSA Algorihtm :
1. Take 2 large prime number p,q and compute n =p*q ( n is called as modulus )
2. Choose number e (given e<n) and relatively prime to z ( where z= (p-1)*(q-1) )
i.e. z and e have no common factor except 1.
3. Find another number d such that (ed-1) is divisible by z;
where e is called as Public Exponent
d is called as Private Exponent
n is called as modulus
(n,e) is called as Public Key.
(n,d) is called as Private Key.
*/
/* Computing Y = X^e mod n using algorithm Binary Left-to-Right method
Let e is represented in base 2 as e= e(k-1) e(k-2)...e(0).
where e(k-1) = MSB (nonzero) and e(0) = LSB (nonzero)
Algorithm :
set Y = X;
for bit j = k-2 to Zero
begin
Y = Y*Y mod n;
if e(j)==1 then
Y = Y*X mod n;
end
return Y;
*/
// computing binary equivalent of e
for(i=0;i<100;i++)
b[i]=0;
len=0;
while(e>0)
{
mod =e%2;
b[len]=mod;
e=e/2;
len++;
}
/* read each character till end of file */
while ( ( read(fps, buf, 1) ) == 1)
{
value=*buf;
ch = (int)value;
if(ch<0)
ch=256+ch;
c=ch;
for(j=len-2;j>=0;j--)
{
c=(c*c) % n;
if(b[j]==1)
c=(c*ch) % n;
} //end for
if(c<100)
{
count=0;
buffer[0]=BLANK;
buffer[1]=BLANK;
buffer[2]=(char)assign(c);
buffer[3]='\0';
flag=write(fpt,buffer,3);
}//end of if(c<100)
if(c>=100)
{
i=0;
while(c>=100)
{
out= c % 100;
output[i]=assign(out);
c=c/100;
i++;
if(c<100)
{
output[i]=(char)assign(c);
if(i<2)
output[2]=BLANK;
c=c/100;
}
}//end of while
output[3]='\0';
w=0;
for(j=2;j>=0;j--)
{
buffer[w]=(char)output[j];
w++;
} // end of for (j=0.....)
buffer[w]='\0';
flag=write(fpt,buffer,3);
}// end of if (c>=100)
if ( flag == -1 )
break;
}// end of else reading file
if ( flag == -1 )
{
printf("\a");
writestring( " Unable to encrypt file !", 11, 8, 32);
close ( fps ) ;
close ( fpt ) ;
}
else
writestring( " File sucessfully encrypted!", 11, 8, 32);
getch() ;
close ( fps ) ;
close ( fpt ) ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
}// end of while reading file
}//end of function encryption
//////////////////////////////////////////////////////////
/* function to decrypt a encrypted file*/
decryptfile()
{
char *buf,*ptr;
char sfile[20], tfile[20], *p,s1[5],psw[4],buffer[3],value,output[10];
char s2[4]="srs",s3[4]="SRS",value1,value2;
FILE *fps, *fpt ;
int areareqd, flag, a, i, j, k, result,x,b[100],mod,test,g;
int count, ch, z,len,w,bytes,val,val1,val2;
unsigned long int n,c,out,d,power1,power2,sum;
buf = malloc(1);
areareqd = ( 23 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
printf("\a");
writestring ( messages[4], 22, 11, 32 ) ;
getch() ;
size(32,0);
return ;
}
savevideo ( 5, 5, 23, 70, p ) ;
menubox ( 6, 5, 13, 60, 32);
writestring ( " File decode service ", 22, 11, 164 ) ;
writestring ( "Enter source file name:", 7, 8, 32 ) ;
size ( 6, 7 ) ;
gotoxy ( 33, 8 ) ;
getkey();
if (ascii==ESC)
{
//restore original screen contents
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
gets ( sfile ) ;
size ( 32, 0 ) ;
getkey();
k=strlen(sfile);
/* // to make sure that file name is entered or not
if( k <= 0 )
{
printf("\a");
writestring ( messages[0], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
return ;
} */
for(i=0;i<k;i++)
{
if(sfile[i]!='.')
j=0;
if(sfile[i]=='.')
{
j=1;
n=k-2-i;
for(a=0;a<=n;a++)
{
s1[a]=sfile[i+1];
i++;
}
}
}
s1[a+1]='\0';
if(j==0)
{
printf("\a");
writestring ( messages[1], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free(p);
return ;
}
else
{
n=0;
for(i=0;i<strlen(s2);i++)
{
if( ( s1[i]==s2[i] ) || ( s1[i]==s3[i] ) )
n++;
}
if( n!=3)
{
printf("\a");
writestring ( messages[2], 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free(p);
return ;
}
else
{
/* open source file */
fps= open ( sfile, O_RDONLY | O_BINARY, S_IREAD ) ;
if ( fps == -1 )
{
printf("\a");
writestring ( "Source file not found!", 9, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
return ;
}
writestring ( "Enter the keys of decryption n : ", 9, 8, 32 ) ;
writestring ( " d : ", 10, 8, 32 ) ;
size ( 6, 7 );
gotoxy ( 47, 10 );
getkey();
if (ascii==ESC)
{
//close file and restore original screen contents
close ( sfile );
restorevideo(5,5,23,70,p);
free ( p );
size(32,0);
return;
}
scanf("%lu", &n);
gotoxy ( 47, 11 );
scanf("%lu", &d);
size ( 32, 0 ) ;
k=strlen(sfile);
for(i=0;i<k;i++)
{
if(sfile[i]=='.')
{
j=1;
z=k-2-i;
for(a=0;a<=z;a++)
{
s1[a]=sfile[i+1];
i++;
}
}
}
s1[a+1]='\0';
for(i=0;i<k;i++)
{
if( sfile[i]=='.' )
{
sfile[i+1]='d';
sfile[i+2]='e';
sfile[i+3]='c';
sfile[i+4]='\0';
break;
}
}
// to make filename of encrypted file as sourcefile.srs
strcpy(tfile,sfile);
/* open target file */
fpt = open ( tfile,O_CREAT | O_TRUNC| O_WRONLY | O_BINARY,S_IREAD | S_IWRITE );
// computing binary equivalent of d
for(i=0;i<50;i++)
b[i]=0;
len=0;
while(d>0)
{
mod =d%2;
b[len]=mod;
d=d/2;
len++;
}
while ( ( test = read ( fps,buf, 3) ) > 0)
{
buf[3]='\0';
sum=0;
g=0;
value=buf[g];
val=check(value);
value1=buf[g+1];
val1=check(value1);
value2=buf[g+2];
val2=check(value2);
power1=val*pow(100,2);
power2=val1*100;
sum=val2+power1+power2;
g=g+3;
c=sum;
for(j=len-2;j>=0;j--)
{
c=(c*c) % n;
if(b[j]==1)
c=(c*sum) % n;
} //end of for loop
flag=write(fpt,&c,1);
if ( flag == -1 )
break;
} // end of while reading file
if ( flag == -1 )
{
printf("\a");
writestring ( "Unable to decrypt file!", 11, 8, 32 ) ;
close ( fps ) ;
close ( fpt ) ;
}
else
writestring ( "File successfully decrypted!", 11, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
close ( fps ) ;
close ( fpt ) ;
restorevideo ( 5, 5, 23, 70, p ) ;
free ( p ) ;
}
}//end of file read
}// end of function
//****************************************
/* To display a file*/
displayfile()
{
char *p,*ptr1,*ptr2,*ptr3,*ptr4, filename[20], ch, str[5] ;
int pg = 1, row = 2, col = 1, area ,k;
FILE *fp ;
area = ( 25 - 0 + 1 ) * ( 82 - 0 + 1 ) * 2 ;
p = malloc ( area ) ;
if ( p == NULL )
{
printf("\a");
writestring ( messages[4], 22, 14, 27 ) ;
getch() ;
return ;
}
savevideo ( 0, 0, 24, 81, p ) ;
menubox ( 5, 5, 10, 60, 32 ) ;
writestring ( " File display service ", 22, 14, 164 ) ;
writestring ( "Enter name of file:", 6, 8, 32 ) ;
size ( 6, 7 ) ;
gotoxy ( 29, 7 ) ;
getkey();
if (ascii==ESC)
{
// restore original screen contents
restorevideo(0,0,24,81,p);
free ( p );
size(32,0);
return;
}
gets ( filename ) ;
size ( 32, 0 ) ;
k=strlen(filename);
// to make sure that file name is entered or not
if( k <= 0 )
{
printf("\a");
writestring ( messages[0], 8, 8, 32 ) ;
writestring ( messages[3], 22, 11, 164 ) ;
getch() ;
restorevideo ( 0, 0, 24, 81, p ) ;
free ( p ) ;
return ;
}
ptr1=strstr(filename,".txt");
ptr2=strstr(filename,".srs");
ptr3=strstr(filename,".dec");
ptr4=strstr(filename,".obj");
if( (ptr1==NULL) && (ptr2==NULL) && (ptr3==NULL) && (ptr4==NULL) )
{
printf("\a");
writestring("Non text files can't be displayed!",8,8,32);
writestring ( messages[3], 22, 14, 164 ) ;
getch() ;
restorevideo ( 0, 0, 24, 81, p ) ;
free ( p ) ;
return ;
}
/* open file to be displayed */
fp = fopen ( filename, "r" ) ;
if ( fp == NULL )
{
printf("\a");
writestring ( "Source file not found!", 8, 8, 32 ) ;
writestring ( messages[3], 22, 14, 164 ) ;
getch() ;
restorevideo ( 0, 0, 24, 81, p ) ;
free ( p ) ;
return ;
}
menubox ( 0, 0, 1, 80, 27 ) ;
menubox ( 1, 0, 24, 80, 27 ) ;
drawbox ( 1, 0, 23, 79, 27 ) ;
drawbox ( 1, 0, 21, 79, 27 ) ;
writechar ( 21, 0, 204, 27 ) ;
writechar ( 21, 79, 185, 27 ) ;
/* display file name and current page number */
writestring ( "File :-", 0, 0, 27 ) ;
writestring ( filename, 0, 8, 27 ) ;
writestring ( "Page No :- ", 0, 67, 27 ) ;
itoa ( pg, str, 10 ) ;
writestring ( str, 0, 78, 27 ) ;
/* read each character till end of file is reached */
while ( ( ch = getc ( fp ) ) != EOF )
{
/* if character read is not a newline, carriage return or tab */
if ( ( ch != '\n' ) && ( ch != '\r' ) && ( ch != '\t' ) )
writechar ( row, col, ch, 27 ) ;
/* if tab, increment column by 4 otherwise by 1 */
if ( ch == '\t' )
col += 4 ;
else
col++ ;
/* if column exceeds 75 or end of line is met */
if ( col > 75 || ch == '\n' )
{
col = 1 ;
row++ ;
/* if screen is full */
if ( row > 19 )
{
writestring ( messages[3], 22, 17, 155 ) ;
getch() ;
row = 2 ;
pg++ ;
menubox ( 2, 1, 20, 77, 27 ) ;
writestring ( "File :-", 0, 0, 27 ) ;
writestring ( filename, 0, 8, 27 ) ;
writestring ( "Page No :- ", 0, 67, 27 ) ;
itoa ( pg, str, 10 ) ;
writestring ( str, 0, 78, 27 ) ;
}
}
}
printf("\a");
writestring ( " Press any key to return... ", 22, 14, 155 ) ;
getch() ;
fclose ( fp ) ;
restorevideo ( 0, 0, 24, 81, p ) ;
free ( p ) ;
}
//////////////////////////////////////////////////////////
/* displays product information */
about()
{
int area ;
char *p ;
size ( 32, 0 ) ; /* hide cursor */
/* allocate memory, if unsuccessful terminate execution */
area = ( 18 - 6 + 1 ) * ( 60 - 19 + 1 ) * 2 ;
p = malloc ( area ) ;
if ( p == NULL )
error_exit() ;
/* create dialogue box */
savevideo ( 6, 19, 17, 60, p ) ;
menubox ( 6, 19, 17, 60, 144);
drawbox ( 6, 19, 16, 58 , 144 ) ;
writestring ( " ", 7, 22, 79) ;
writestring ( " Designed & Written ", 8, 22, 79 ) ;
writestring ( " by ", 9, 22, 79 ) ;
writestring ( " Ritu Verma & Sunita Sah ", 10, 22, 194 ) ;
writestring ( " At ", 11, 22, 79 ) ;
writestring ( " CITM Sec - 43, Aravalli Hills ", 12, 22, 79 ) ;
writestring ( " Delhi - Faridabad Road ", 13, 22, 79 ) ;
writestring ( " ", 14, 22, 79 ) ;
writestring ( " ", 15, 22, 79 ) ;
/* display OK button */
menubox ( 15, 33, 16, 42, 110);
writestring ( "OK", 15, 36, 110 ) ;
/* continue till either Esc is hit or OK is selected */
while ( 1 )
{
getkey() ;
if ( ascii == ESC || ascii != 'O' || ascii == 'o' )
break ;
}
restorevideo ( 6, 19, 17, 60, p ) ;
free ( p ) ;
size(32,0);
}
//////////////////////////////////////////////////////////
/* To display relevent information regarding the use of application*/
helptopic()
{
int area ;
char *p ;
size ( 32, 0 ) ; /* hide cursor */
/* allocate memory, if unsuccessful terminate execution */
area = ( 23 - 1 + 1 ) * ( 80 - 0 + 1 ) * 2 ;
p = malloc ( area ) ;
if ( p == NULL )
error_exit() ;
/* create dialogue box */
savevideo(1, 0, 23, 79, p ) ;
menubox ( 1, 1, 23, 80, 110);
drawbox ( 1, 0, 23, 79, 110 ) ;
writestring ( "Encryption: ", 3, 3, 111) ;
writestring ( "This software is works successfully only for TEXT FILES. ", 3, 15,110 ) ;
writestring ( "To write cipher text,software itself creates a new file with the name ", 4,3,110 ) ;
writestring ( "similar to the source file but with extension SRS. For encryption,use ",5,3,110 ) ;
writestring ( "only those keys given in the File named List_keys .",6,3,110 ) ;
writestring ( "Decryption: ", 8, 3, 111) ;
writestring ( "For decryption input file must be encrypted one,otherwise in ", 8, 15,110);
writestring ( "target file you will get garbage instead of original text.For decryption ", 9, 3,110 ) ;
writestring ( "enter source file having SRS extension only.Software by itself will create", 10,3,110 );
writestring ( "file with extension DEC containing original data.For decryption,use only ",11,3,110);
writestring ( "those keys given in the File named List_keys i.e.enter d corresponding to",12,3,110);
writestring ( "(n,e) used in encryption.",13,3,110);
writestring ( "Shortcut keys used are: ", 15, 3, 111) ;
writestring ( "ALT+F-->File", 17, 4, 107 ) ;
writestring ( "CTRL+C-->Copy", 18, 4, 110 ) ;
writestring ( "CTRL+D-->Delete", 19, 4, 110 ) ;
writestring ( "CTRL+E-->Encrypt", 20, 4, 110 ) ;
writestring ( "CTRL+Y-->Decrypt", 21, 4, 110 ) ;
writestring ( "CTRL+I-->Display", 22, 4, 110 ) ;
writestring ( "ALT+H-->Help", 17, 25, 107 ) ;
writestring ( "CTRL+A-->About Application", 18, 25, 110 ) ;
writestring ( "CTRL+P-->Help Topics", 18, 25, 110 ) ;
writestring ( "ALT+E-->Exit", 17, 54, 107 ) ;
writestring ( "ALT+X-->Exit the ", 18, 54, 110 ) ;
writestring ( "application ", 19, 62, 110 ) ;
/* display OK button */
menubox ( 22, 34, 23, 41, 79);
writestring ( "OK", 22, 36, 79 ) ;
/* continue till either Esc is hit or OK is selected */
while ( 1 )
{
getkey() ;
if ( ascii == ESC || ascii==13 || ascii != 'O' || ascii == 'o' )
break ;
}
restorevideo(1, 0, 23, 79, p ) ;
free ( p ) ;
size(32,0);
}
//////////////////////////////////////////////////////////
/* displays the logo on the screen */
logo()
{
int i, j ;
for ( i = 0 ; i <= 25 ; i++ )
{
for ( j = 0 ; j <= 79 ; j++ )
writechar ( i, j, 176, 8) ;
writechar ( i, j, 176, 8 ) ;
}
drawbox ( 2, 21, 15, 60, 79 ) ;
writestring ( " *********************************** ", 3,22,79 ) ;
writestring ( " ", 4,22,79 ) ;
writestring ( " CRYPTOGRAPHY ", 5,22,78 ) ;
writestring ( " ", 6,22,79 ) ;
writestring ( " *********************************** ", 7,22,79 ) ;
writestring ( " Press any key... ", 19,22,207 ) ;
getch() ;
}
//////////////////////////////////////////////////////////
/* To create the password screen*/
pswscreen()
{
int i, j, count, x, y, len1, len2,a,b ;
char uid[7],psw[7],c_uid1[]="project",c_uid2[]="crypto";
for ( i = 0 ; i <= 24 ; i++ )
{
for ( j = 0 ; j <= 78 ; j++ )
writechar ( i, j, 176, 4) ;
writechar ( i, j, 176, 4 ) ;
}
drawbox( 3, 17, 18, 62, 79 ) ;
menubox( 4, 18, 18, 63, 79 ) ;
writestring ( " ", 4,18,79 ) ;
writestring ( " AUTHENTICATION TEST ", 5,18,79 ) ;
writestring ( " ", 6,18,79 ) ;
writestring ( " Enter User ID - ", 7,18,79 ) ;//37,8
writestring ( " Enter Password - ", 10,18,79 ) ;
writestring ( " ", 8,18,79 ) ;
writestring ( " ", 9,18,79 ) ;
writestring ( " ", 11,18,79 ) ;
writestring ( " ", 12,18,79 ) ;
/* display OK button */
menubox ( 15, 30, 16, 37, 110);
writestring ( "OK", 15, 32, 110 ) ;
/* display CANCEL button */
menubox ( 15, 40, 16, 49, 110);
writestring ( "CANCEL", 15, 41, 110 ) ;
size ( 6, 7 ) ;
gotoxy ( 37, 8 ) ;
// check for key pressed
getkey() ;
// if ESC key is pressed, then also You can enter the application else check for psw entered
if ( ascii == ESC )
{
return;
}
else
{
count=0;
while(count<=3)
{
size ( 6, 7 ) ;
gotoxy ( 37, 8 ) ;
gets ( uid ) ;
size ( 32, 0 ) ;
size ( 6, 7 ) ;
gotoxy ( 37, 11 ) ;
gets ( psw ) ;
size ( 32, 0 ) ;
if( ( len1=strlen(uid) <=0 ) || (len2=strlen(psw) <=0) )
{
printf("\a");
writestring ( " Please enter User ID and Password!", 13, 20,207 ) ;
getch();
writestring ( " ",13,18,79 ) ;
writestring ( " ",7,36,79 ) ;
writestring ( " ",10,36,79 ) ;
count++;
}
else
{
x=strcmp(c_uid1,uid);
y=strcmp(c_uid1,psw);
a=strcmp(c_uid2,uid);
b=strcmp(c_uid2,psw);
if ( (x==0) && (y==0) || (a==0) && (b==0) )
return;
if( ( (x!=0) || (y!=0) )|| ((x!=0) && (y!=0) ) ||( (a!=0) || (b!=0) )|| ((a!=0) && (b!=0) ) )
{
printf("\a");
writestring ( " Please enter correct User ID and Password!", 13, 18,207 ) ;
count++;
getch();
writestring ( " ",13,18,79 ) ;
writestring ( " ",7,36,79 ) ;
writestring ( " ",10,36,79 ) ;
}// end of if
}//end of else
if(count==3)
{
clrscr() ;
exit(0);
}
}// end of while
}// end of else
}// end of function pswscreen
No comments:
Post a Comment