You are on page 1of 52

# Geethanjali College Engineering and Technology

Department Of CSE

Lab: C and Data Structures

* Write C program that implement the following sorting methods to sort a given list of integers in
ascending order:
ii) Merge sort */

#include <stdio.h>
#include <stdlib.h>

#define MAX_ARY 10

void merge_sort(int x[], int end, int start);

int main(void) {
int ary[MAX_ARY];
int j = 0;

printf("\n\nEnter the elements to be sorted: \n");
for(j=0;j<MAX_ARY;j++)
scanf("%d",&ary[j]);

/* array before mergesort */
printf("Before :");
for(j = 0; j < MAX_ARY; j++)
printf(" %d", ary[j]);

printf("\n");

merge_sort(ary, 0, MAX_ARY - 1);

/* array after mergesort */
printf("After Merge Sort :");
for(j = 0; j < MAX_ARY; j++)
printf(" %d", ary[j]);

printf("\n");
getch();
}

/* Method to implement Merge Sort*/
void merge_sort(int x[], int end, int start) {
int j = 0;
const int size = start - end + 1;
int mid = 0;
int mrg1 = 0;
int mrg2 = 0;
int executing[MAX_ARY];

if(end == start)
return;

mid = (end + start) / 2;

merge_sort(x, end, mid);
merge_sort(x, mid + 1, start);

Page 1

Geethanjali College Engineering and Technology
Department Of CSE

for(j = 0; j < size; j++)
executing[j] = x[end + j];

mrg1 = 0;
mrg2 = mid - end + 1;

for(j = 0; j < size; j++) {
if(mrg2 <= start - end)
if(mrg1 <= mid - end)
if(executing[mrg1] > executing[mrg2])
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
else
x[j + end] = executing[mrg2++];
else
x[j + end] = executing[mrg1++];
}
}

Page 2

Geethanjali College Engineering and Technology
Department Of CSE

* Write C programs that implement Queue (its operations) using ii) Pointers */

#define true 1
#define false 0

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

struct q_point
{
int ele;
struct q_point* n;
};

struct q_point *f_ptr = NULL;

int e_que(void);
int rem_ele(void);
void show_ele();

/*main function*/
void main()
{
int ele,choice,j;
while(1)
{
clrscr();
printf("\n\n****IMPLEMENTATION OF QUEUE USING POINTERS****\n");
printf("==============================================");
printf("==============================================");
printf("\n\t[1] To insert an element");
printf("\n\t[2] To remove an element");
printf("\n\t[3] To display all the elements");
printf("\n\t[4] Exit");
scanf("%d", &choice);

switch(choice)
{
case 1:
{
printf("\n\tElement to be inserted:");
scanf("%d",&ele);
getch();
break;
}

case 2:
{
if(!e_que())

Page 3

Geethanjali College Engineering and Technology
Department Of CSE

{
j=rem_ele();
printf("\n\t%d is removed from the queue",j);
getch();
}
else
{
printf("\n\tQueue is Empty.");
getch();
}
break;
}

case 3:
show_ele();
getch();
break;

case 4:
exit(1);
break;

default:
printf("\n\tInvalid choice.");
getch();
break;
}

}
}

/* Function to check if the queue is empty*/
int e_que(void)
{
if(f_ptr==NULL)
return true;
return false;
}

/* Function to add an element to the queue*/
{
struct q_point *queue = (struct q_point*)malloc(sizeof(struct q_point));
queue->ele = ele;
queue->n = NULL;
if(f_ptr==NULL)
f_ptr = queue;
else
{
struct q_point* ptr;
ptr = f_ptr;
for(ptr=f_ptr ;ptr->n!=NULL; ptr=ptr->n);
ptr->n = queue;
}
}

Page 4

Geethanjali College Engineering and Technology
Department Of CSE

/* Function to remove an element from the queue*/
int rem_ele()
{
struct q_point* queue=NULL;
if(e_que()==false)
{
int j = f_ptr->ele;
queue=f_ptr;
f_ptr = f_ptr->n;
free (queue);
return j;
}
else
{
printf("\n\tQueue is empty.");
return -9999;
}
}

/* Function to display the queue*/
void show_ele()
{
struct q_point *ptr=NULL;
ptr=f_ptr;
if(e_que())
{
printf("\n\tQUEUE is Empty.");
return;
}
else
{
printf("\n\tElements present in Queue are:\n\t");
while(ptr!=NULL)
{
printf("%d\t",ptr->ele);
ptr=ptr->n;
}
}
}

Page 5

h> struct st_point { int ele. getch(). printf("\n======================================"). while(1) { clrscr(). } case 2: { num2=pop_ele(1). printf("\n\tEnter your choice: "). Geethanjali College Engineering and Technology Department Of CSE /* Write C programs that implement stack (its operations) using ii) Pointers */ #include<stdio. void push_ele(int j). break. switch(choice-'0') { case 1: { printf("\n\tElement to be pushed:"). scanf("%c". fflush(stdin). printf("\n[4] Exit\n"). printf("\n\t\t MENU ").&num1). struct st_point *l. printf("\n[3] Elements present in Stack"). scanf("%d".num2). int i. break. } case 3: Page 6 .num1=0. int pop_ele().num2=0.&choice). printf("\n[2] Using Pop Function"). push_ele(num1).h> #include<conio. void main() { char choice. printf("\n\tElement to be popped: %d\n\t". printf("======================================"). void display_ele(). printf("\n[1] Using Push Function"). } *t. int i.

break. } } } /*Inserting the elements using push function*/ void push_ele(int j) { struct st_point *m. break. break. getch().\n"). default: printf("\nYour choice is invalid. m->l=t. } return 0. } case 4: exit(1). exit(1). } /*Displaying the elements */ void display_ele() { struct st_point *pointer=NULL. return (i). Page 7 . } /*Removing the elements using pop function*/ int pop_ele() { if(t==NULL) { printf("\n\STACK is Empty. t=m.").pointer->ele). while(pointer!=NULL) { printf("%d\t". pointer=t. display_ele(). } else { int i=t->ele. getch(). m=(struct st_point*)malloc(sizeof(struct st_point)). return. t=t->l. m->ele=j. Geethanjali College Engineering and Technology Department Of CSE { printf("\n\tElements present in the stack are:\n\t").

Geethanjali College Engineering and Technology Department Of CSE pointer=pointer->l. } } Page 8 .

int a). printf("-----------------------------------------------------\n").&num).h> struct treenode { int ele. int num. scanf("%d". printf("Enter your choice:"). scanf("%d". if(choice>0 & choice<=3) { printf("\nEnter the number of nodes:"). } switch(choice) { case 1: Page 9 . void TraverseInorder(struct treenode *t). clrscr().&value). void TraversePreorder(struct treenode *t). /*main function*/ void main() { struct treenode *root_node = NULL. Geethanjali College Engineering and Technology Department Of CSE /* Write a C program that uses functions to perform the following: i) Creating a Binary Tree of integers ii) Traversing the above binary tree in preorder. inorder and postorder. while(num-.h> #include<conio. printf("\t\t\tMENU\n").h> #include <stdlib. printf("[2] Create a Binary Tree and Use Preorder Traversal\n").value. printf("[1] Create a Binary Tree and Use Inorder Traversal\n"). struct treenode *insert_node(struct treenode *t. int choice. printf("[3] Create a Binary Tree and Use Postorder Traversal\n"). struct treenode *l_child. void TraversePostorder(struct treenode *t).> 0) { printf("\n\nEnter the data value:"). printf("----------------------------------------------------\n").value).&choice). *r_child. */ #include<stdio. printf("-----------------------------------------------------\n"). root_node = insert_node(root_node. }. scanf("%d".

} else { temp_node1 = t. getch(). TraversePreorder(root_node). break. default: printf("Invalid Choice"). if(t == NULL) { printf("Value cannot be allocated. } t->ele = a. if( temp_node1 ->ele > a) temp_node1 = temp_node1->l_child. break. getch().int a) { struct treenode *temp_node1. else temp_node1 = temp_node1->r_child. exit(0). TraverseInorder(root_node). } } } /*end main*/ /* Function to create a Binary Tree of integers data */ struct treenode *insert_node(struct treenode *t. if(t == NULL) { t = (struct treenode *) malloc(sizeof(struct treenode)). Geethanjali College Engineering and Technology Department Of CSE printf("\n\nBinary tree using Inorder Traversal : "). Page 10 . break. break. TraversePostorder(root_node). t->l_child=t->r_child=NULL. getch(). while(temp_node1 != NULL) { temp_node2 = temp_node1.*temp_node2. case 2: printf("\n\nBinary tree using Preorder Traversal : "). } if( temp_node2->ele > a) { temp_node2->l_child = (struct treenode*)malloc(sizeof(struct treenode)).\n"). case 3: printf("\n\nBinary tree using Postorder Traversal : ").

\n"). } temp_node2->ele = a.t->ele). } temp_node2->ele = a. TraversePostorder(t->r_child). printf("%d\t". exit(0). */ void TraverseInorder(struct treenode *t) { if(t != NULL) { TraverseInorder(t->l_child). temp_node2->l_child=temp_node2->r_child = NULL.t->ele). exit(0). } /* Function for Traversing the binary tree in inorder. */ void TraversePreorder(struct treenode *t) { if(t != NULL) { printf("%d\t". } else { temp_node2->r_child = (struct treenode*)malloc(sizeof(struct treenode)). Geethanjali College Engineering and Technology Department Of CSE temp_node2 = temp_node2->l_child. } } return(t). if(temp_node2 == NULL) { printf("Value cannot be allocated. in_order(t->r_child). if(temp_node2 == NULL) { printf("Value cannot be allocated.\n"). temp_node2 = temp_node2->r_child. TraversePreorder(t->l_child). } } /* Function for Traversing the binary tree in preorder. temp_node2->l_child=temp_node2->r_child = NULL. */ void TraversePostorder(struct treenode *t) { if(t != NULL) { TraversePostorder(t->l_child). TraversePreorder(t->r_child). } } /* Function for Traversing the binary tree in postorder. Page 11 .

} } Page 12 . Geethanjali College Engineering and Technology Department Of CSE printf("%d\t".t->ele).

sum=0. sum+=i.i<n.h> #include <sys/types. sum+=i.i<n.h> #include <unistd. pid_t pid.i+=2) { printf(“%d\”.&n) pid=fork().sum). scanf(“%d”.sum).i).n. } printf(“Odd sum:%d\n”. } else { printf(“From process\n”).i+=2) { printf(“%d\”.h> int main() { int i.h> #include <fcntl. printf(“Enter n value:”).i). Geethanjali College Engineering and Technology Department Of CSE LAB: UNIX Programming Write a C program that illustrates the creation of child process using fork system call. } } Page 13 . One process finds sum of even series and other process finds sum of odd series #include <stdio. for(i=1. } printf(“Even sum:%d\n”. system(“clear”). for(i=0. if(pid==0) { printf(“From child process\n”).

seqno++.n)!=n) Page 14 .arg)<0) perror(“semctl”). pid.buff. } pid=getpid(). Seq no:%d\n”. short *array. seqno).01.n. lseek(fd. i.0. exit(1). int main(]) { int child. void my_lock(int). lseek(fd. if((semid=semget(KEY. struct semid_ds *buf.2))<0) { perror(“open”). if(semctl(semid. pid. Geethanjali College Engineering and Technology Department Of CSE Write a C program that illustrates file locking using semaphores.MAXBUF))<0) { perror(“read”).SETVAL. } arg. 1.i++) { my_lock(fd).i<2.h> #include <error.val=1.fd. n=strlen(buff).h> #include <sys/sem. IPC_CREAT | 0666))= = -1) { perror(“semget”).h> #define MAXBUF 100 #define KEY 1216 #define SEQFILE “suhritfile” int semid. if(write(fd. }arg.0).01. if((fd=open(SEQFILE.buff. char buff[MAXBUF+1]. exit(1).h> #include <sys/file. seqno.0). sprintf(buff. void my_unlock(int). #include <stdio. pid=getpid().”%d\n”. for(i=0. if((n=read(fd. union semnum { int val. seqno). } printf(“pid:%d. exit(1).

else printf(“Error in Lock\n”). 0). exit(1). Geethanjali College Engineering and Technology Department Of CSE { perror(“write”). &sbuf. } void my_unlock(int fd) { struct sembuff sbuf=(0. 1. 0). } Page 15 . my_unlock(fd). &sbuf. } sleep(1). else printf(“Error in Unlock\n”). 1)= =0) printf(“UnLocking: Resource…\n”). if(semop(semid. if(semop(semid. 1)= =0) printf(“Locking: Resource…\n”). } } void my_lock(int fd) { struct sembuff sbuf=(0. -1.

int end. Page 16 . String str) method. /* To replace the contents of Java StringBuffer use StringBuffer replace(int start.println("Original Text : " + sb).out.5. Geethanjali College Engineering and Technology Department Of CSE LAB: Object Oriented Programming Java StringBuffer Replace Example /* Java StringBuffer Replace Example This example shows how contents of java StringBuffer can be replaced using replace method of Java StringBuffer class. System. It replaces the content from StringBuffer string from start index to end ."Hi"). */ public class JavaStringBufferReplaceExample { public static void main(String[] args) { //Create the StringBuffer object StringBuffer sb = new StringBuffer("Hello World").1 index by the content of the String str.replace(0. */ sb.

Geethanjali College Engineering and Technology Department Of CSE System.out.println("Replaced Text : " + sb). } } /* Output would be Original Text : Hello World Replaced Text : Hi World Page 17 .

try { Page 18 .FileInputStream.dat".FileOutputStream.io.dat". Geethanjali College Engineering and Technology Department Of CSE Copy binary file using Streams /* Copy binary file using Streams This example shows how to copy a binary file using Java FileInputStream and FileOutputStream classes. import java.FileNotFoundException. import java. public class CopyBinaryFile { public static void main(String[] args) { String strSourceFile="C:/FileIO/source. String strDestinationFile="C:/FileIO/dest.io. */ import java.io.io. If you want to copy text file use FileReader and FileWriter classes instead of FileInputStream and FileOutputStream classes.IOException. import java.

int noOfBytes = 0. } catch(FileNotFoundException fnf) Page 19 . //read bytes from source file and write to destination file while( (noOfBytes = fin.close(). //close the streams fin. //create FileOutputStream object for destination file FileOutputStream fout = new FileOutputStream(strDestinationFile). Geethanjali College Engineering and Technology Department Of CSE //create FileInputStream object for source file FileInputStream fin = new FileInputStream(strSourceFile). System. noOfBytes). fout. byte[] b = new byte[1024]. } System. 0.println("File copied!").write(b.close().println("Copying file using streams").out.out.read(b)) != -1 ) { fout.

} catch(IOException ioe) { System.println("Error while copying file :" + ioe). Geethanjali College Engineering and Technology Department Of CSE { System.println("Specified file not found :" + fnf).out. } } } /* Typical output would be Copying file using streams File copied! Page 20 .out.

It also describes how to add something to TreeMap and how to retrieve the value added from TreeMap. */ Page 21 . Object put(Object key. /* Add key value pair to TreeMap using. */ import java. Geethanjali College Engineering and Technology Department Of CSE Simple Java TreeMap example /* Simple Java TreeMap example This simple Java Example shows how to use Java TreeMap. Object value) method of Java TreeMap class.util.TreeMap. public class JavaTreeMapExample { public static void main(String[] args) { //create object of TreeMap TreeMap treeMap = new TreeMap(). where key and value both are objects put method returns Object which is either the value previously tied to the key or null if no value mapped to the key.

Java Primitive values CAN NOT be added directly to TreeMap. System. The value must be casted to the original class. new Integer(2)). Geethanjali College Engineering and Technology Department Of CSE treeMap. It must be converted to corrosponding wrapper class first.put("One".println(obj). */ //retrieve value using Object get(Object key) method of Java TreeMap class Object obj = treeMap. treeMap.put("Two". /* Please note that put method accepts Objects.out. /* Please note that the return type of get method is an Object. */ } } /* Output of the program would be 2 Get lowest and highest key stored in Java TreeMap example Page 22 .get("Two"). new Integer(1)).

treeMap. Page 23 . treeMap.TreeMap."Two"). */ import java."Four"). Geethanjali College Engineering and Technology Department Of CSE /* Get lowest and highest key stored in Java TreeMap example This Java Example shows how to get the lowest and highest key stored in the java TreeMap object using firstKey and lastKey methods of java TreeMap class. treeMap."Three").put("3". public class GetLowestHighestKeyTreeMapExample { public static void main(String[] args) { //create TreeMap object TreeMap treeMap = new TreeMap()."One").put("1". treeMap.util."Five"). //add key value pairs to TreeMap treeMap.put("2". Object firstKey() method of TreeMap class.put("5". /* To get the lowest key currently stored in Java TreeMap use.put("4".

out.firstKey()). */ System. /* To get the highest key currently stored in Java TreeMap use. */ System.println("Highest key Stored in Java TreeMap is : " + treeMap. Object lastKey() method of TreeMap class. Geethanjali College Engineering and Technology Department Of CSE This method returns the first or lowest key currently stored in the TreeMap object.lastKey()).out.println("Lowest key Stored in Java TreeMap is : " + treeMap. } } /* Output would be Lowest key Stored in Java TreeMap is : 1 Page 24 . This method returns the last or highest key currently stored in the TreeMap object.

Geethanjali College Engineering and Technology Department Of CSE Highest key Stored in Java TreeMap is : 5 */ Page 25 .

h> #include<conio.i<3. break.k.l. for(i=0.i<3. } for(i=0. } for(j=0.2}. int p[12]={2. clrscr().k<12.frsize=3.h> int fr[3].i<3.flag1=0.found=0.2.index. } } } if(flag2==0) { for(i=0.3.i++) { if(fr[i]==-1) { fr[i]=p[j].j.i<frsize. flag2=1. void main() { void display().fs[3].5.i<3.1.i++) { lg[i]=0.j++) { flag1=0.5. } } if(flag1==0) { for(i=0.flag2=0. break. Page 26 . flag2=1. Geethanjali College Engineering and Technology Department Of CSE LAB: Operating Systems PROGRAM FOR OPTIMAL ALGORITHM #include<stdio. flag2=0. for(i=0. break.4.3. int max.pf=0.j<12.lg[3].i++) { if(fr[i]==p[j]) { flag1=1.i.i++) { for(k=j+1.2.k++) { if(fr[i]==p[k]) { lg[i]=k-j.i++) { fr[i]=-1.2.5.

} } } fr[index]=p[j]. } } if(found==0) { max=lg[0].i<frsize. } void display() { int i. } display(). for(i=1. } OUTPUT : 2 -1 -1 2 3 -1 2 3 -1 2 3 1 2 3 5 2 3 5 4 3 5 4 3 5 4 3 5 2 3 5 2 3 5 2 3 5 Page 27 .i++) { if(lg[i]==0) { index=i.pf). for(i=0. printf("\n"). Geethanjali College Engineering and Technology Department Of CSE } } } found=0.i<3. index=0.i++) { if(max<lg[i]) { max=lg[i]. found=1. } printf("\n no of page faults:%d". for(i=0.i<frsize. getch(). index=i. pf++.fr[i]).i++) printf("\t%d". break.

Geethanjali College Engineering and Technology Department Of CSE no of page faults : 3 Page 28 .

&c[i][j]).j<=5.i<=5. for(i=1. } if(sum==0) { m[k]=i. clrscr(). for(j=1. k++. printf("enter clain matrix"). } printf("enter availability vector:\n").&r[i]).l. printf("enter total no of processes").i.j<=5.tp. } printf("enter allocation matrix").a[5].l++) if(i!=m[l]) { flag=1. for(i=1.l<k.k=1.flag.i<=5.j<=5.r[5].j++) { scanf("%d". temp[i]=a[i].j++) { sum+=p[i][j].temp[5].i++) for(j=1.j++) { scanf("%d". scanf("%d". } for(i=1. for(i=1.p[4][5]. } printf("enter resource vector:\n").&p[i][j]).j<=5.i++) { scanf("%d".h> #include<conio.i++) for(j=1.h> void main() { int found.i++) { sum=0.i<=4. for(j=1.i++) { for(l=1.&tp).j++) if(c[i][j]>temp[j]) Page 29 .i++) { scanf("%d".m[5]. } } for(i=1.i<=4. Geethanjali College Engineering and Technology Department Of CSE PROGRAM FOR DEADLOCK #include<stdio.sum=0.c[4][5].i<=4. for(i=1.i<=4.&a[i]).j.

j++) { found=0. } } printf("deadlock causing processes are:"). } INPUT: enter total no.j). of processes : 4 enter claim matrix : 01001 00101 00001 10101 enter allocation matrix : 10110 11000 00010 00000 enter resource vector : 21121 enter the availability vector : 00001 OUTPUT : deadlock causing processes are : 1 2 Page 30 . } if(found==0) printf("%d\t".i<k.j<=5. for(i=1.i++) { if(j==m[i]) found=1. k++. } } if(flag==1) { m[k]=i. Geethanjali College Engineering and Technology Department Of CSE { flag=0.j++) temp[j]+=p[i][j].j<=tp. for(j=1. for(j=1. } getch(). break.

&p[i][j]).j<=5. printf("enter clain matrix").temp[5]. } } for(i=1. printf("enter total no of processes"). } printf("enter availability vector:\n").tp. k++.j++) { sum+=p[i][j].h> void main() { int found.i++) { scanf("%d".j++) { scanf("%d".k=1.sum=0. } printf("enter resource vector:\n"). for(j=1. clrscr().flag. for(j=1. for(i=1.r[5].l.&a[i]).i++) for(j=1.j++) Page 31 .i++) { scanf("%d".m[5].j<=5.j<=5. } printf("enter allocation matrix").&tp).j.i<=4.i++) { sum=0.&c[i][j]).&r[i]).h> #include<conio. for(i=1. Geethanjali College Engineering and Technology Department Of CSE PROGRAM FOR DEADLOCK DETECTION ALGORITHM #include<stdio.i<=4.j<=5. for(i=1.c[4][5].i<=4. } if(sum==0) { m[k]=i.i<=5.i++) { for(l=1.l++) if(i!=m[l]) { flag=1.l<k.j++) { scanf("%d".p[4][5]. temp[i]=a[i].a[5]. scanf("%d". } for(i=1.i++) for(j=1.i<=5.i. for(i=1.i<=4.

i<k.i++) { if(j==m[i]) found=1. break.j<=5. for(j=1. for(i=1. Geethanjali College Engineering and Technology Department Of CSE if(c[i][j]>temp[j]) { flag=0. of processes : 4 enter claim matrix : 01001 00101 00001 10101 enter allocation matrix : 10110 11000 00010 00000 enter resource vector : 21121 enter the availability vector : 00001 OUTPUT : deadlock causing processes are : 1 2 Page 32 . } INPUT: enter total no.j). k++.j<=tp.j++) temp[j]+=p[i][j]. } getch(). } } if(flag==1) { m[k]=i. } } printf("deadlock causing processes are:"). for(j=1. } if(found==0) printf("%d\t".j++) { found=0.

i++) if(b[i]!=0) cout<<a[0][i]<<"----"<<b[i]<<"\n".j++) { if(a[0][i]==a[1][j]) { a[1][j]='\$'. void main() { char a[1][50]. clrscr().h> #include<stdio.i++) { b[i]=0. strcpy(a[1]. cout<<"Enter the text:".h> #include<iostream. for(i=0. gets(a[0]).j<n. } } } for(i=0.b[50]. for(j=0. b[i]++.a[0]).i<n.h> int n. Geethanjali College Engineering and Technology Department Of CSE LAB: Information Security Program implementing Monoalphabetic Cipher #include<conio.i<n. getch().j. } Page 33 . int i. n=strlen(a[0]).h> #include<string.

gets(d[0]).i<3. void main() { clrscr(). Page 34 .j.i.j<3.i<3.m++) c[i][j]+=k[i][m]*p[m][j].l[3][3]. cout<<"\n". cout<<"DECRYPTION PROCESS:\n". cout<<"Entered key matrix is:\n".k[3][3].b[3][3].a[1][26]={"abcdefghijklmnopqrstuvwxyz"}.m<3.i<3.i++) for(j=0. cout<<"Enter the key matrix:\n".i<26.i++) { c[i][0]%=26. } } cout<<"The plain matrix is:\n". for(i=0.i<3. for(i=0.i++) { for(j=0. } for(i=0. puts(d[0]). char d[1][10].i++) { if(a[0][i]==d[0][j]) { p[j][0]=i. } cout<<"The cipher text matrix is\n".o.j<1.e[1][10].j++) cout<<k[i][j]<<" ".h> #include<math.p[3][1].i<3. cout<<c[i][0]<<"\n". int det. break.j<3. for(j=0.i++) cout<<p[i][0]<<"\n".j++) for(i=0.i++) for(j=0.j<3. strcpy(d[0].j++) cin>>k[i][j]. for(m=0.h> #include<string. cout<<"The enterted text is:".h> #include<graphics. //convertion of cipher data to plain data clrscr(). cout<<"Enter the key:".h> #include<stdio.j++) { c[i][j]=0.h> int c[3][1]. for(i=0. } getch().m.n. Geethanjali College Engineering and Technology Department Of CSE Program implementing Hill cipher #include<conio. for(i=0.h> #include<iostream.strlwr(d[0])).

for(i=0. } getch(). b[2][2]=k[0][0]*k[1][1]-k[1][0]*k[0][1].i++) { for(j=0. b[1][1]=k[0][0]*k[2][2]-k[2][0]*k[0][2].j<3. } cout<<"The inverse of the key matrix is:\n". for(m=0. b[0][0]=k[1][1]*k[2][2]-k[2][1]*k[1][2].i<3.i<3.i<3. cout<<e[i][0].j++) { int h=i+j. b[1][2]=k[0][0]*k[2][1]-k[2][0]*k[0][1]. for(i=0.i++) for(j=0.j<1. } for(i=0.j<3. b[2][1]=k[0][0]*k[1][2]-k[1][0]*k[0][2].i++) for(j=0. e[i][0]=a[0][j]. cout<<"1/"<<det. b[1][0]=k[0][1]*k[2][2]-k[2][1]*k[0][2]. b[2][0]=k[0][1]*k[1][2]-k[1][1]*k[0][2]. } Page 35 .i<3. b[i][j]=pow(-1. det=m-n+o.j++) cout<<b[i][j]<<" ". b[0][2]=k[1][0]*k[2][1]-k[2][0]*k[1][1]. } //contertion of plain data to plain text cout<<"The entered plain text is:\n". b[0][1]=k[1][0]*k[2][2]-k[2][0]*k[1][2]. n=k[0][1]*(k[1][0]*k[2][2]-k[1][2]*k[2][0]). cout<<"\n".i<3. for(i=0.m++) p[i][j]+=b[i][m]*c[m][j]*(1/det). } cout<<"The plain text matrix is\n".m<3. cout<<p[i][0]<<"\n". for(i=0. Geethanjali College Engineering and Technology Department Of CSE m=k[0][0]*(k[1][1]*k[2][2]-k[1][2]*k[2][1]). o=k[0][2]*(k[1][0]*k[2][1]-k[2][0]*k[1][1]).j++) { p[i][j]=0.i++) { j=p[i][0].h)*b[i][j].i++) { p[i][0]%=26.

gets(k[0]).a[0]). for(i=0. n=strlen(k[0]).c[1][26].j++) if(b[j]!=0) { k[2][i]=k[0][j]. j++. cout<<"Enter the key:". o++. strcpy(k[1]. for(i=0.h> #include<iostream.j=0.j++) if(k[0][i]==a[1][j]) a[1][j]='\$'.i<5. puts(k[0]). for(j=0.i++) Page 36 .j<n.h> #include<stdio.l++.l.i<n.i<26.j<26.} cout<<"The Playfair cipher matrix is:\n".h> #include<string.j++) for(l=0. } n1=strlen(k[2]).j<n.n1. for(i=0.j++) { if(k[0][i]==k[1][j]) { k[1][j]='\$'. strcpy(a[1]. strcpy(k[0].j<5.k[0]). else {m[j][l]=a[2][o].p[1][26].l<5. Geethanjali College Engineering and Technology Department Of CSE Program implementing PlayFair Cipher #include<conio. cout<<"The enterted text is:".i++) if(i<n1) m[j][l]=k[2][i]. int b[26].n. i++.strlwr(k[0])). void main() { clrscr().j=0.m[5][5]. for(j=0. } } } for(i=0.o=0. } for(i=0. char k[3][25].i++) for(j=0.a[4][26]={"abcdefghijklmnopqrstuvwxyz"}.h> int i.i++) if(a[1][i]!='\$') {a[2][j]=a[1][i].i<n. b[i]++.j.i++) { b[i]=0. i=0.

getch().i++) for(j=0. for(i=0. Geethanjali College Engineering and Technology Department Of CSE { for(j=0.i<5. cout<<"\nThe cipher text is:\n".j++) if(c[0][i]==a[3][j]) p[0][i]=a[0][j]. puts(c[0]).i<n. } a[3][l]=a[2][o].j<5. cout<<"\nThe decryption process starts now:\n". for(i=0. } Page 37 .j++) cout<<m[i][j]<<" ". getch(). cout<<"\nThe Encryption process starts now:".j<5. l=0. l++.i++) for(j=0. for(i=0. cout<<"The plain text is:\n". } cout<<a[2][o]. getch().i<n. cout<<"\n".i++) for(j=0.j++) if(k[0][i]==a[0][j]) c[0][i]=a[3][j].j<26. puts(p[0]).j<26.j++) { a[3][l]=m[i][j].

ta=new JTextArea(5. ta. class PortCheckFrame extends JFrame { JTextArea ta. ta. setSize(300.swing.add(new JScrollPane(ta)). Geethanjali College Engineering and Technology Department Of CSE Program implementing Port Check import java.red). } }.append("checking ports of"+hostname+".i++) try { Socket S=new Socket(hostname. } } Page 38 . setVisible(true).net.awt.20).awt.i). PortCheckFrame() { super("checking ports"). class PortCheck { public static void main(String args[]) { new PortCheckFrame().*. import java.getContentPane().*.append("server is running at port number"+i+"\n").io. String hostname=JOptionPane.setForeground(Color.300). import java. import javax.event..showInputDialog("enter remote host name").i<=1023. Container con=this.*.append("no server is running at port number"+i+"\n"). import java.\n"). } catch(IOException e) { ta. } setDefaultCloseOperation(EXIT_ON_CLOSE). con. ta. for(int i=0.*.*.

</script> </body> </html> OUTPUT The full URL of this document is: http://www.com/jsref/tryit_view. Geethanjali College Engineering and Technology Department Of CSE LAB: Web Technologies Program that Returns URL <html> <body> The full URL of this document is: <script type="text/javascript"> document.write(document.w3schools.asp Page 39 .URL).

target="_blank".Google. Geethanjali College Engineering and Technology Department Of CSE Program to Change Target attribute <html> <head> <script type="text/javascript"> function changeTarget() { document. } </script> </head> <body> <a id="w3s" href="http://www.com">Visit google</a> <br /><br /> <input type="button" onclick="changeTarget()" value="Change target" /> <p>Try the link before and after you have pressed the button!</p> </body> </html> Output Visit Google.getElementById('w3s').com Page 40 .

</script> </p> </body> </html> OUTPUT Value of href attribute for Venus is: http://www. Geethanjali College Engineering and Technology Department Of CSE Program to return the href of an area in an image-map <html> <body> <img src="planets.write(document.58.getElementById("venus").htm" /> </map> <p>Value of href attribute for Venus is: <script type="text/javascript"> document.href).Google.gif" width="145" height="126" usemap="#planetmap" /> <map name="planetmap"> <area id="venus" shape="circle" coords="124.8" alt="Venus" href="venus.htm Page 41 .com/jsref/venus.

Geethanjali College Engineering and Technology Department Of CSE Program to Change the src attribute of an iframe <html> <head> <script type="text/javascript"> function changeSrc() { document.</p> </iframe> <br /><br /> <input type="button" onclick="changeSrc()" value="Change Source" /> </body> </html> Page 42 .com".getElementById("myframe"). } </script> </head> <body> <iframe id="myframe" src="/default.asp"> <p>Your browser does not support iframes.src="http://google.

90</PRICE> <YEAR>1985</YEAR> </CD> − <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.Geethanjali College Engineering and Technology Department Of CSE XML Program For CD catalogue <!-.90</PRICE> <YEAR>1988</YEAR> </CD> − Page 43 .Edited by XMLSpy® --> − <CATALOG> − <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.

20</PRICE> <YEAR>1990</YEAR> </CD> − <CD> <TITLE>Eros</TITLE> <ARTIST>Eros Ramazzotti</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>BMG</COMPANY> <PRICE>9.90</PRICE> <YEAR>1997</YEAR> Page 44 .Geethanjali College Engineering and Technology Department Of CSE <CD> <TITLE>Greatest Hits</TITLE> <ARTIST>Dolly Parton</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>RCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1982</YEAR> </CD> − <CD> <TITLE>Still got the blues</TITLE> <ARTIST>Gary Moore</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin records</COMPANY> <PRICE>10.

Geethanjali College Engineering and Technology Department Of CSE </CD> − <CD> <TITLE>One night only</TITLE> <ARTIST>Bee Gees</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.10</PRICE> <YEAR>1973</YEAR> </CD> − <CD> <TITLE>Maggie May</TITLE> <ARTIST>Rod Stewart</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Pickwick</COMPANY> Page 45 .90</PRICE> <YEAR>1998</YEAR> </CD> − <CD> <TITLE>Sylvias Mother</TITLE> <ARTIST>Dr.Hook</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS</COMPANY> <PRICE>8.

Geethanjali College Engineering and Technology Department Of CSE <PRICE>8.70</PRICE> <YEAR>1987</YEAR> </CD> − <CD> <TITLE>Black angel</TITLE> <ARTIST>Savage Rose</ARTIST> Page 46 .80</PRICE> <YEAR>1996</YEAR> </CD> − <CD> <TITLE>When a man loves a woman</TITLE> <ARTIST>Percy Sledge</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>8.50</PRICE> <YEAR>1990</YEAR> </CD> − <CD> <TITLE>Romanza</TITLE> <ARTIST>Andrea Bocelli</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>10.

70</PRICE> <YEAR>1995</YEAR> </CD> − <CD> Page 47 .Geethanjali College Engineering and Technology Department Of CSE <COUNTRY>EU</COUNTRY> <COMPANY>Mega</COMPANY> <PRICE>10.90</PRICE> <YEAR>1995</YEAR> </CD> − <CD> <TITLE>1999 Grammy Nominees</TITLE> <ARTIST>Many</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Grammy</COMPANY> <PRICE>10.20</PRICE> <YEAR>1999</YEAR> </CD> − <CD> <TITLE>For the good times</TITLE> <ARTIST>Kenny Rogers</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Mucik Master</COMPANY> <PRICE>8.

90</PRICE> <YEAR>1997</YEAR> </CD> − <CD> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Polydor</COMPANY> <PRICE>8.90</PRICE> <YEAR>1996</YEAR> </CD> Page 48 .20</PRICE> <YEAR>1971</YEAR> </CD> − <CD> <TITLE>Soulsville</TITLE> <ARTIST>Jorn Hoel</ARTIST> <COUNTRY>Norway</COUNTRY> <COMPANY>WEA</COMPANY> <PRICE>7.Geethanjali College Engineering and Technology Department Of CSE <TITLE>Big Willie style</TITLE> <ARTIST>Will Smith</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>9.

Geethanjali College Engineering and Technology Department Of CSE − <CD> <TITLE>The very best of</TITLE> <ARTIST>Cat Stevens</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Island</COMPANY> <PRICE>8.90</PRICE> <YEAR>1988</YEAR> </CD> − <CD> <TITLE>Bridge of Spies</TITLE> <ARTIST>T'Pau</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Siren</COMPANY> <PRICE>7.90</PRICE> Page 49 .90</PRICE> <YEAR>1990</YEAR> </CD> − <CD> <TITLE>Stop</TITLE> <ARTIST>Sam Brown</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>A and M</COMPANY> <PRICE>8.

90</PRICE> <YEAR>1983</YEAR> </CD> − <CD> <TITLE>Midt om natten</TITLE> <ARTIST>Kim Larsen</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Medley</COMPANY> <PRICE>7.Geethanjali College Engineering and Technology Department Of CSE <YEAR>1987</YEAR> </CD> − <CD> <TITLE>Private Dancer</TITLE> <ARTIST>Tina Turner</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Capitol</COMPANY> <PRICE>8.80</PRICE> <YEAR>1983</YEAR> </CD> − <CD> <TITLE>Pavarotti Gala Concert</TITLE> <ARTIST>Luciano Pavarotti</ARTIST> <COUNTRY>UK</COUNTRY> Page 50 .

Geethanjali College Engineering and Technology Department Of CSE <COMPANY>DECCA</COMPANY> <PRICE>9.90</PRICE> <YEAR>1987</YEAR> </CD> − <CD> <TITLE>Picture book</TITLE> <ARTIST>Simply Red</ARTIST> <COUNTRY>EU</COUNTRY> <COMPANY>Elektra</COMPANY> <PRICE>7.20</PRICE> <YEAR>1985</YEAR> </CD> − <CD> <TITLE>Red</TITLE> Page 51 .90</PRICE> <YEAR>1991</YEAR> </CD> − <CD> <TITLE>The dock of the bay</TITLE> <ARTIST>Otis Redding</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Atlantic</COMPANY> <PRICE>7.

80</PRICE> <YEAR>1987</YEAR> </CD> − <CD> <TITLE>Unchain my heart</TITLE> <ARTIST>Joe Cocker</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>EMI</COMPANY> <PRICE>8.20</PRICE> <YEAR>1987</YEAR> </CD> </CATALOG> Page 52 .Geethanjali College Engineering and Technology Department Of CSE <ARTIST>The Communards</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>London</COMPANY> <PRICE>7.