Implement On A Data Set of Characters The Three CRC Polynomials - CRC 12, CRC 16 and CRC
Implement On A Data Set of Characters The Three CRC Polynomials - CRC 12, CRC 16 and CRC
Implement on a data set of characters the three CRC polynomials CRC 12, CRC 16 and CRC CCIP
#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]; clrscr(); 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(i=0;i<keylen-1;i++) printf("%c",rem[i]); printf("\nFinal data is: "); for(i=0;i<msglen;i++) printf("%c",input[i]); for(i=0;i<keylen-1;i++) printf("%c",rem[i]); getch(); }
OUTPUT: Enter Data: 11110110101 Enter Key: 111010 Quotient is: 10010010000 Remainder is 00000 Final data is1111011010100000
/* Distance Vector Routing in this program is implemented using Bellman Ford Algorithm:*/ #include<stdio.h> struct node { unsigned dist[20]; unsigned from[20]; }rt[10]; int main() { int costmat[20][20]; int nodes,i,j,k,count=0; printf("\nEnter the number of nodes : "); scanf("%d",&nodes);//Enter the nodes printf("\nEnter the cost matrix :\n"); for(i=0;i<nodes;i++) { for(j=0;j<nodes;j++) { scanf("%d",&costmat[i][j]); costmat[i][i]=0; rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost matrix rt[i].from[j]=j; } } do { count=0; for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct distance from the node i to k using the cost matrix //and add the distance from k to node j for(j=0;j<nodes;j++) for(k=0;k<nodes;k++) if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j]) {//We calculate the minimum distance rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]; rt[i].from[j]=k; count++; } }while(count!=0); for(i=0;i<nodes;i++) { printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++) { printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]); } } printf("\n\n"); getch(); } /* OUTPUT A sample run of the program works as:Enter the number of nodes : 3 Enter the cost matrix : 0 2 7 2 0 1 7 1 0 For router 1 node 1 via 1 Distance 0 node 2 via 2 Distance 2 node 3 via 3 Distance 3 For router 2 node 1 via 1 Distance 2 node 2 via 2 Distance 0 node 3 via 3 Distance 1 For router 3 node 1 via 1 Distance 3 node 2 via 2 Distance 1 node 3 via 3 Distance 0 */