Mono-Alphabetic Encryption


This program is for implementing MONOALPHABETIC encryption . This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

MONOALPHABETIC:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
char *ciper,*plan,*plan2;
clrscr();
puts("\nEnter the sender side text : ");
gets(plan);
puts("\nEnter the Charter difference : ");
scanf("%d",&n);
for(i=0;plan[i]!='\0';i++)
{
if((plan[i]>=65 && plan[i]<=90-n) || (plan[i]>=97 && plan[i]<=122-n))
            ciper[i]=plan[i]+n;
else if((plan[i]>90-n && plan[i]<=90)||(plan[i]>122-n && plan[i]<=122))
            ciper[i]=plan[i]-26+n;
else
            ciper[i]=plan[i];
}
ciper[i]='\0';
puts("\nThe trasmitted data is  : \n");
puts(ciper);

for(i=0;ciper[i]!='\0';i++)
{
if((ciper[i]>=65+n && ciper[i]<=90) || (ciper[i]>=97+n && ciper[i]<=122))
            plan2[i]=ciper[i]-n;
else if((ciper[i]>=65 && ciper[i]<=65+n)||(ciper[i]>=97 && ciper[i]<=97+n))
            plan2[i]=ciper[i]+26-n;
else
            plan2[i]=ciper[i];
}
plan2[i]='\0';
puts("\nThe Reciver side data is  : \n");
puts(plan2);

getch();
}



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

CRC Cyclic Redundancy Check

This program to implement Cyclic Redundancy Check (CRC). This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

#include<stdio.h>
#include<conio.h>
int rem(int,int);
void main()
{
  int i,j,k,dl,dil;
  int data[10],div[5],newdata[15],crc[5],datacrc[15],revdata[15],remd[5];
  clrscr();
  printf("\n Enter the data length= ");
  scanf("%d",&dl);
  printf("\n Enter the divisor  length= ");
  scanf("%d",&dil);
  printf("\n Enter the data : ");
  for(i=0;i<dl;i++)
   scanf("%d",&data[i]);
  printf("\n Enter the divisor : ");
  for(i=0;i<dil;i++)
   scanf("%d",&div[i]);
  printf("\n The new data is : ");
  for(i=0;i<(dl+dil-1);i++)
  {
    if(i<dl)
     newdata[i]=data[i];
    else
     newdata[i]=0;
    printf("%d",newdata[i]);
  }
 for(j=0;j<=dl;j++)
 {
            for(i=0;i<dil;i++)
            {
             crc[i]=newdata[i+j];
             if(crc[0]==1)
              newdata[i+j]=rem(newdata[i+j],div[i]);
             else
              newdata[i+j]=rem(newdata[i+j],0);
            }
 printf("\n The Crc is : ");
 for(i=0;i<dil-1;i++)
  printf("%d",crc[i]);
 }

 printf("\n The data to be send is : ");
 for(i=0;i<(dl+dil-1);i++)
 {
  if(i<dl)
   datacrc[i]=data[i];
  else
   datacrc[i]=crc[i-dl];
  printf("%d",datacrc[i]);
 }
 printf("\n Enter the receiver side data : ");
 for(i=0;i<(dl+dil-1);i++)
  scanf("%d",&revdata[i]);
  for(j=0;j<=dl;j++)
 {
            for(i=0;i<dil;i++)
            {
             remd[i]=revdata[i+j];
             if(remd[0]==1)
              revdata[i+j]=rem(revdata[i+j],div[i]);
             else
              revdata[i+j]=rem(revdata[i+j],0);
            }
 printf("\n The reminder is : ");
 k=0;
 for(i=0;i<dil-1;i++)
  {
  printf("%d",remd[i]);
   if(remd[i]==0)
    k++;
  }
 }
 if(k==dil-1)
 printf("\n There is no error found.");
 else
 printf("\n There is error found.");
 getch();
}

int rem(int x, int y)
{
 if(x==y)
  return 0;
 else
  return 1;
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Spanning Tree DS and DCN

This program is for implementing Spanning Tree. This is a part of Mumbai University MCA Colleges Data Communication and Networking And Data Structure MCA

#include<stdio.h>
#include<alloc.h>
#define MAX 20
struct edge
{
int u;
int v;
int weight;
struct edge *link;
}*front = NULL;

int father[MAX];
struct edge tree[MAX];
int n;
int wt_tree=0;
int count=0;
void make_tree();
void insert_tree(int i,int j,int wt);
void insert_pque(int i,int j,int wt);
void create_graph();
struct edge *del_pque();
void main()
{
int i;
clrscr();
create_graph();
make_tree();
printf("\nEdges to be included in spanning tree are :\n");
for(i=1;i<=count;i++)
{
printf("%d->",tree[i].u);
printf("%d\n",tree[i].v);
}
printf("\n\nWeight of this minimum spanning tree is : %d\n", wt_tree);
getch();
}


void create_graph()
{
int i,wt,max_edges,origin,destin;
printf("Enter number of nodes : ");
scanf("%d",&n);
max_edges=n*(n-1)/2;
for(i=1;i<=max_edges;i++)
{
printf("Enter edge %d(0 0 to quit): ",i);
scanf("%d %d",&origin,&destin);
if( (origin==0) && (destin==0) )
break;
printf("Enter weight for this edge : ");
scanf("%d",&wt);

if( origin > n || destin > n || origin<=0 || destin<=0)
{
printf("Invalid edge!\n");
i--;
}
else
insert_pque(origin,destin,wt);
}
}

void make_tree()
{
struct edge *tmp;
int node1,node2,root_n1,root_n2;

while( count < n-1)
{
tmp=del_pque();
node1=tmp->u;
node2=tmp->v;

while( node1 > 0)
{
root_n1=node1;
node1=father[node1];
}


while( node2 >0 )
{
root_n2=node2;
node2=father[node2];
}

if(root_n1!=root_n2)
{
insert_tree(tmp->u,tmp->v,tmp->weight);
wt_tree=wt_tree+tmp->weight;
father[root_n2]=root_n1;
}
}
}

void insert_tree(int i,int j,int wt)
{
count++;
tree[count].u=i;
tree[count].v=j;
tree[count].weight=wt;
}

void insert_pque(int i,int j,int wt)
{
struct edge *tmp,*q;

tmp = (struct edge *)malloc(sizeof(struct edge));
tmp->u=i;
tmp->v=j;
tmp->weight = wt;

if( front == NULL || tmp->weight < front->weight )
{
tmp->link = front;
front = tmp;
}


else
{
q = front;
while(q->link != NULL && q->link->weight <= tmp->weight)
q=q->link;
tmp->link = q->link;
q->link = tmp;

if(q->link == NULL)
tmp->link = NULL;
}
}
struct edge *del_pque()
{
struct edge *tmp;
tmp = front;
front = front->link;
return tmp;
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Walsh Matrix DCN

This program is for implementing Walsh Matrix. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

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

int walsh[8][8]={1};
int walshnxt[8][8]={0};

void copy(int cnt)
{
int i, j, k;

for(i=0; i<cnt; i++)
{
for(j=0; j<cnt/2; j++)
{
          if(i < cnt/2)

          {
  walshnxt[i][j]=walsh[i][j];
  walshnxt[i][j+(cnt/2)]=walsh[i][j];
          }
          else
          {
  k=i-(cnt/2);
  walshnxt[i][j]=walsh[k][j];
  if(walsh[k][j] == 1)
    walshnxt[i][j+(cnt/2)]=-1;
           else
    walshnxt[i][j+(cnt/2)]=1;
           }
          }
}

for(i=0; i<7; i++)
{
for(j=0; j<7; j++)
{
walsh[i][j]=walshnxt[i][j];
}
}

}

void main()
{
 int num, i, j, cntr;
 clrscr();
 printf("Enter the power of 2: ");
 scanf("%d", &num);
 walsh[0][0]=1;
 cntr=1;
 for(i=2; i <= pow(2, num);i=pow(2, cntr))
 {
   copy(i);
   cntr++;
 }
printf("\n\n\n");
 if(num==0)
   printf("\t1");
 else
   for(i=0;i<pow(2,num);i++)
   {
    for(j=0;j<pow(2,num);j++)
    {
     printf("\t %d", walshnxt[i][j]);
    }
    printf("\n");
   }
 getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

RSA Algorithm Network Security


This program is for implementing RSA Algorithm. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4
#include< stdio.h>
#include< conio.h>

int phi,M,n,e,d,C,FLAG;

int check()
{
int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG = 1;
return;
}
FLAG = 0;
}

void encrypt()
{
int i;
C = 1;
for(i=0;i< e;i++)
C=C*M%n;
C = C%n;
printf("\n\tEncrypted keyword : %d",C);
}

void decrypt()
{
int i;
M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
printf("\n\tDecrypted keyword : %d",M);
}

void main()
{
int p,q,s;
clrscr();
printf("Enter Two Relatively Prime Numbers\t: ");
scanf("%d%d",&p,&q);
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do
{
printf("\n\nEnter e\t: ");
scanf("%d",&e);
check();
}while(FLAG==1);
d = 1;
do
{
s = (d*e)%phi;
d++;
}while(s!=1);
d = d-1;
printf("\n\tPublic Key\t: {%d,%d}",e,n);
printf("\n\tPrivate Key\t: {%d,%d}",d,n);
printf("\n\nEnter The Plain Text\t: ");
scanf("%d",&M);
encrypt();
printf("\n\nEnter the Cipher text\t: ");
scanf("%d",&C);
decrypt();
getch();
}



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Polyalphabetic Encryption C/C++

This program is for implementing Poly-Alphabetic Encryption. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,k=0;
char *ciper,*plan,*plan2;
clrscr();
puts("\nEnter the sender side text : ");
gets(plan);
puts("\nEnter the groups of character : ");
scanf("%d",&n);
for(i=0;plan[i]!='\0';i=i+n)
{
 k++;
 for(j=i;j<i+n;j++)
 {
  if((plan[j]>=65 && plan[j]<=90-k) || (plan[j]>=97 && plan[j]<=122-k))
            ciper[j]=plan[j]+k;
  else if((plan[j]>90-k && plan[j]<=90)||(plan[j]>122-k && plan[j]<=122))
            ciper[j]=plan[j]-26+k;
  else
            ciper[j]=plan[j];
 }
}
ciper[j]='\0';
puts("\nThe trasmitted data is  : \n");
puts(ciper);
k=0;
for(i=0;ciper[i]!='\0';i=i+n)
{
 k++;
 for(j=i;j<i+n;j++)
 {
  if((ciper[j]>=65+k && ciper[j]<=90) || (ciper[j]>=97+k && ciper[j]<=122))
            plan2[j]=ciper[j]-k;
  else if((ciper[j]>=65 && ciper[j]<=65+k)||(ciper[j]>97 && ciper[j]<=97+k))
            plan2[j]=ciper[j]+26-k;
  else
            plan2[j]=ciper[j];
 }
}
plan2[j]='\0';
puts("\nThe Reciver side data is  : \n");
puts(plan2);
getch();
}



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Shortest Path DCN

This program is for Finding Shortest Path. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

#include<stdio.h>
#include<conio.h>
#define size 100
int mat[size][size],v[size],nt[size],wt[size],t;
int newmat[size][size];
char ch[size][2];
int src,dest;
void print(int arr[size][size])
{
            int i,j;
            printf("%s\t"," ");
            for(i=0;i<t;i++)
                        printf("%s\t",ch[i]);
            printf("\n");
            for(i=0;i<t;i++)
            {
                        printf("%s\t",ch[i]);
                        for(j=0;j<t;j++)
                                    printf("%d\t",arr[i][j]);
                        printf("\n");
            }
}
void sink(int node)
{
            int i,j;
            v[node]=1;
            if(all_visit())
                        return;
            else
            {
                        for(i=0;i<t;i++)
                        {
//                                  print(newmat);
//                                  for(j=0;j<t;j++)
//                                              printf("(%s %s %d)\n",ch[j],ch[nt[j]],wt[j]);
//                                  getch();
                                    if(v[i]==0&&mat[node][i])
                                    {
                                                nt[i]=node;
                                                wt[i]=wt[node]+mat[node][i];
                                                newmat[node][i]=wt[i];
                                                newmat[i][node]=wt[i];
                                                sink(i);
                                    }
                                    else
                                    {
                                                if(v[i]==1&&mat[node][i]&&(wt[node]+mat[node][i])<wt[i])
                                                {
                                                            newmat[i][nt[i]]=0;
                                                            newmat[nt[i]][i]=0;
                                                            nt[i]=node;
                                                            wt[i]=wt[node]+mat[node][i];
                                                            newmat[node][i]=wt[i];
                                                            newmat[i][node]=wt[i];
                                                }
                                    }
                        }
            }
}
void clear()
{
            int i,j;
            for(i=0;i<t;i++)
            {
                        for(j=0;j<t;j++)
                        {
                                    mat[i][j]=0;
                                    newmat[i][j]=0;
                        }
                        v[i]=0;
                        wt[i]=0;
                        nt[i]=(i==src)?0:-1;
            }
}
int all_visit()
{
            int i;
            for(i=0;i<t;i++)
                        if(v[i]==0)
                                    return 0;
            return 1;
}
void main()
{
            int i,j,s,sel;
            clrscr();
            printf("\nEnter the Total Number of Node.\n");

            scanf("%d",&t);
            for(i=0;i<t;i++)
                        scanf("%s",&ch[i]);
            clear();
            for(i=0;i<t;i++)
            {
                        do
                        {
                                    printf("\nEnter the total Link for the Node %s:\n",ch[i]);
                                    scanf("%d",&s);
                        }while(!(s>=0&&s<=t));
                        for(j=0;j<s;j++)
                        {
                                    printf("\nEnter the node number\n");
                                    scanf("%d",&sel);
                                    printf("\nEnter the Weight.\n");
                                    scanf("%d",&mat[i][sel]);
                                    mat[sel][i]=mat[i][sel];
                        }
            }
            printf("\nThe Original Tree\n");
            print(mat);
            printf("\n\nEnter the nodes for which you want to find the shortest path:\t");
            scanf("%d",&src);
            printf("\nEnter the destination:\t");
            scanf("%d",&dest);
            sink(src);


            printf("\nShortest Path is %d\n",wt[dest]);
            print(newmat);
            for(i=0;i<t;i++)
                        printf("(%s %s %d)",ch[i],ch[nt[i]],wt[i]);
            getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Walsh Matrix fixed power

This program is for implementing WALSH MATRIX . This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

#include<stdio.h>
#include<conio.h>
void main()
{
int choice, *arr, i, order, size;
char ans;
do
{
clrscr();
printf("List of operations:\n");
printf("\n1. Walsh Matrix of order 1");
printf("\n2. Walsh Matrix of order 2");
printf("\n3. Walsh Matrix of order 4");
printf("\n0.Exit ");
printf("\n\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
order = 1;
size = order*order;
arr[0] = 1;
arr[size]='\0';
break;
case 2:
order = 2;
size = order*order;
for(i=0;i<size;i++)
arr[i] = 1;
arr[3] = -1;
break;
case 3:
order = 4;
size = order*order;
for(i=0;i<size;i++)
arr[i] = 1;
arr[5] = -1;
arr[7] = -1;
arr[10] = -1;
arr[11] = -1;
arr[13] = -1;
arr[14] = -1;
break;
case 0:
exit();
break;
default:
printf("\nINVALID OPTION..\n\n");
}
printf("\n\nWalsh Matrix of order %d :\n\n",choice);
for(i=0;i<size;i++)
{
if(i%order == 0)
printf("\n");
printf("%3d",arr[i]);
}
getch();
}while(1);
arr[size]=0;
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.


Polyalphabetic Encryption C / C++


This program is for implementing Poly-Alphabetic Encryption. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
            int i,j=0;
            int tmp1,tmp2;
            int dtln,kln,sum;
            char data[100],key[100],cipher[100];

            clrscr();

            printf("Enter String : ");
            gets(data);
            printf("Enter Key : ");
            gets(key);

            dtln=strlen(data);
            kln=strlen(key);
// Sender Side
            for(i=kln;i<dtln;i++)
            {
                        if(data[i]==32)
                        {
                                    i++;
                        }
                        key[i]=key[j];
                        j++;
            }

            for(i=0;i<dtln;i++)
            {
                   if(data[i]==32)
                   {
                        cipher[i]=' ';
                        i++;
                   }
                   else if(data[i]<=90 && data[i]>=65)
                   {
                                    tmp1=data[i]-65;
                   }
                   else if(data[i]<=123 && data[i]>=97)
                   {
                                    tmp1=data[i]-97;
                   }

                   tmp2=key[i]-64;
                   sum=tmp1+tmp2;

                   if(sum>26)
                   {
                                    sum=sum-26;
                                    cipher[i]=sum+64;
                   }
                   else
                   {
                                    cipher[i]=sum+64;
                   }
            }
            cipher[i++]='\0';
            puts(cipher);
//RECEIVER SIDE
            printf("Receiver Side\n");
            for(i=0;cipher[i]!='\0';i++)
            {
                   tmp1=cipher[i]-64;
                   tmp2=key[i]-65;
                   sum=tmp1-tmp2;

                   if(sum<0)
                   {
                                    sum=sum+26;
                                    cipher[i]=sum+64;
                   }
                   else
                   {
                                    cipher[i]=sum+64;
                   }
            }
            cipher[i++]='\0';
            printf(“\n\nCipher Text :”);
            puts(cipher);
            getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.