Skip to main content

Posts

Showing posts from October, 2016

File Allocation Programs

Linked File allocation #include<stdio.h> #include<conio.h> struct fileTable { char name[20]; int nob; struct block *sb; }ft[30]; struct block { int bno; struct block *next; }; void main() { int i, j, n; char s[20]; struct block *temp; printf("Enter no of files   :"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter file name %d :",i+1); scanf("%s",ft[i].name); printf("Enter no of blocks in file %d :",i+1); scanf("%d",&ft[i].nob); ft[i].sb=(struct block*)malloc(sizeof(struct block)); temp = ft[i].sb; printf("Enter the blocks of the file :"); scanf("%d",&temp->bno); temp->next=NULL; for(j=1;j<ft[i].nob;j++) { temp->next = (struct block*)malloc(sizeof(struct block)); temp = temp->next; scanf("%d",&temp->bno); } temp->next = NULL; } printf("\nEnter the file name to be searched --...

CPU Schedueling programs

        Fcfs program         #include<stdio.h> #include<conio.h> main() { int bt[20], wt[20], tat[20], i, n; float wtavg, tatavg; printf("\nEnter the number of processes -- "); scanf("%d", &n); for(i=0;i<n;i++) { printf("\nEnter Burst Time for Process %d -- ", i); scanf("%d", &bt[i]); } wt[0] = wtavg = 0; tat[0] = tatavg = bt[0]; for(i=1;i<n;i++) { wt[i] = wt[i-1] +bt[i-1]; tat[i] = tat[i-1] +bt[i]; wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i]; } printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n"); for(i=0;i<n;i++) printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]); printf("\nAverage Waiting Time -- %f", wtavg/n); printf("\nAverage Turnaround Time -- %f", tatavg/n); getch(); } Output SJF program #include<stdio.h> #include<conio.h> main() { int p[20], bt[20], wt[20],...

CRC-Cyclic Redundancy Check Program

#include <stdio.h>  #include <conio.h>  #include <string.h>  void main() { int i,j,keylen,msglen; char input[100], key[30],temp[30],quot[100],rem[30],key1[30]; printf("Enter Data: "); gets(input); printf("Enter Key: "); gets(key); keylen=strlen(key); msglen=strlen(input); strcpy(key1,key); for (i=0;i<keylen-1;i++) { input[msglen+i]='0'; } for (i=0;i<keylen;i++) temp[i]=input[i]; for (i=0;i<msglen;i++) { quot[i]=temp[0]; if(quot[i]=='0') for (j=0;j<keylen;j++) key[j]='0'; else for (j=0;j<keylen;j++) key[j]=key1[j]; for (j=keylen-1;j>0;j--) { if(temp[j]==key[j]) rem[j-1]='0'; else rem[j-1]='1'; } rem[keylen-1]=input[i+keylen]; strcpy(temp,rem); } strcpy(rem,temp); printf("\nQuotient is "); for (i=0;i<msglen;i++) printf("%c",quot[i]); printf("\nRemainder is "); for...

RSA Algorithm For Encryption and Decryption

#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<math.h> #include<string.h> long int p,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i; char msg[100]; int prime(long int); void ce(); long int cd(long int); void encrypt(); void decrypt(); void main() { printf("\nENTER FIRST PRIME NUMBER\n"); scanf("%d",&p); flag=prime(p); if(flag==0) { printf("\nWRONG INPUT\n"); getch(); exit(1); } printf("\nENTER ANOTHER PRIME NUMBER\n"); scanf("%d",&q); flag=prime(q); if(flag==0||p==q) { printf("\nWRONG INPUT\n"); getch(); exit(1); } printf("\nENTER MESSAGE\n"); fflush(stdin); scanf("%s",msg); for (i=0;msg[i]!=NULL;i++) m[i]=msg[i]; n=p*q; t=(p-1)*(q-1); ce(); printf("\nPOSSIBLE VALUES OF e AND d ARE\n"); for (i=0;i<j-1;i++) printf("\n%ld\t%ld",e[i],d[i]); encrypt(); decrypt(); getch(); } int prime(long i...

Dijkstra Algorithm

Program to find the shortest path #include<stdio.h> #include<string.h> #include<math.h> #define IN 99 #define N 6 int dijkstra(int cost[][N], int source, int target); int dijsktra(int cost[][N],int source,int target) {     int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j;     char path[N];     for(i=1;i< N;i++)     {         dist[i] = IN;         prev[i] = -1;     }     start = source;     selected[start]=1;     dist[start] = 0;     while(selected[target] ==0)     {         min = IN;         m = 0;         for(i=1;i< N;i++)         {             d = dist[start] +cost[start][i];             if(d< dist[i]&&selected[i]==0)       ...

Byte Stuffing

//PROGRAM FOR CHARACTER STUFFING #include<stdio.h> #include<string.h> #include<process.h> void main() { int i=0,j=0,n,pos; char a[20],b[50],ch; printf("enter string\n"); scanf("%s",&a); n=strlen(a); printf("enter position\n"); scanf("%d",&pos); if(pos>n) { printf("invalid position, Enter again :"); scanf("%d",&pos);} printf("enter the character\n"); ch=getche(); b[0]='d'; b[1]='l'; b[2]='e'; b[3]='s'; b[4]='t'; b[5]='x'; j=6; while(i<n) { if(i==pos-1) { b[j]='d'; b[j+1]='l'; b[j+2]='e'; b[j+3]=ch; b[j+4]='d'; b[j+5]='l'; b[j+6]='e'; j=j+7; } if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e') { b[j]='d'; b[j+1]='l'; b[j+2]='e'; j=j+3; } b[j]=a[i]; i++; j++; } b[j]='d'; b[j+...

Bit Stuffing Program

#include<stdio.h> main() { int i,j,k,n,count=0; int a[30],b[30]; printf("The flag is 01111110"); printf("\n Enter the message size:"); scanf("%d",&n); printf("\n Enter the message in bits(0/1):"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\n The message is:"); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("\n"); for(i=0,j=0;i<n;i++,j++) { if(a[i]==1) { if(count==5) { b[j]=0; j++; count=0; } else count++; b[j]=a[i]; } k=j; printf("\n The coded message is:"); printf("01111110 /t"); for(j=0;j<k;j++) { printf("%d",b[j]); } printf("\01111110\n"); count=0; printf("The encoded message is :\n"); printf("\n 01111110 \t"); for(i=0;i<k;i++) { if(b[i]==1 && count<5) { printf("%d",b[i]...

Subnet Of Hosts

#include<stdio.h> int p,q,u,v,n; int min=99,mincost=0; int t[50][2],i,j; int parent[50],edge[50][50]; main() { //clrscr(); printf("\n Enter the number of nodes"); scanf("%d",&n); for(i=0;i<n;i++) { printf("%c\t",65+i); parent[i]=-1; } printf("\n"); for(i=0;i<n;i++) { printf("%c",65+i); for(j=0;j<n;j++) scanf("%d",&edge[i][j]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) if(edge[i][j]!=99) if(min>edge[i][j]) { min=edge[i][j]; u=i; v=j; } p=find(u); q=find(v); if(p!=q) { t[i][0]=u; t[i][1]=v; mincost=mincost+edge[u][v]; sunion(p,q); } else { t[i][0]=-1; t[i][1]=-1; } min=99; } printf("Minimum cost is %d\n Minimum spanning tree is\n" ,mincost); for(i=0;i<n;i++) if(t[i][0]!=-1 && t[i][1]!=-1) { printf("%c %c %d", 65+t[i][0], 65+t[i][1], edge[t[i][0]][t[i][1]]); printf("\n"); } } sunion(int l,int m) { paren...

DES Coding

DES algorithm #include<stdio.h> //#include<conio.h> #include<string.h> #include<malloc.h> #include<stdlib.h> #include<math.h> void hex_to_bin(char *,char *); char* bin_to_hex(char *); void permutation(char *,char *); void make_half(char *,char *,char *); void single_shift(char *,char *); void double_shift(char *,char *); void make_key(char *,char *,char *); void permutation_32(char *,char *); void permutation_48(char *,char *); void permutation_64(char *,char *,char *); void des_round(char *,char *,char *,char *,char *,char *,char *); void des_round_decry(char *,char *,char *,char *,char *,char *,char *); void copy(char *,char *); void permut_48(char *,char *); void xor(char *,char *,char *); void xor_32(char *,char *,char *); void common_permutation(char *,char *); void hex_to_plain(char *,char *,int); int switch_case(char ); char SB[32]; char *bin[]={  "0000",  "0001",  "0010",  ...