forked from 8BitSec/CN_practicals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cn_1.c
74 lines (53 loc) · 1.42 KB
/
cn_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<stdio.h>
int main()
{
int n,m;
int i;
printf("\n\nEnter the size of message: "); scanf("%d",&n);
int arr[n],temp[10];
printf("\n\nEnter the message (in binary): ");
for(i=0; i<n; i++) scanf("%d", &arr[i]);
for(i=0;i<n;i++) temp[i]=arr[i];
printf("\nMessage entered is: ");
for(int i=0;i<n;i++) printf("%d",arr[i]);
printf("\n\nEnter the size of generator: ");
scanf("%d",&m);
int arr1[m];
printf("\n\nEnter the message generator(in binary): ");
for(int i=0;i<m;i++) scanf("%d",&arr1[i]);
printf("\nMessage after reduntant bits is: ");
for(int i=n;i<(n+m-1);i++) arr[i]=0;
for(int i=0;i<(n+m-1);i++) printf("%d", arr[i]);
for(int i=0;i<n;i++)
{
if(arr1[0]==arr[i])
{
for(int j=0 ,k=i;j<m;j++,k++)
{
if( !( arr[k] ^ arr1[j] ) ) arr[k]=0;
else arr[k]=1;
}
}
}
printf("\n\nCRC bits at sender's side are: ");
for(int i=n;i<(n+m-1);i++) printf("%d",arr[i]);
int arr2[n+m];
printf("\nEnter the message( with CRC's bits) at reciever's end: ");
for(int i=0;i<(n+m-1);i++) scanf("%d",&arr2[i]);
printf("\nMessage recieved is: ");
for(int i=0;i<(n+m-1);i++) printf("%d",arr2[i]);
for(int i=0;i<n;i++)
{
if(arr1[0]==arr2[i])
{
for(int j=0 ,k=i;j<m;j++,k++)
{
if( !( arr2[k] ^ arr1[j] ) ) arr2[k]=0;
else arr2[k]=1;
}
}
}
printf("\n\nCRC bits at reciever's side are: ");
for(int i=n;i<(n+m-1);i++) printf("%d",arr2[i]);
return 0;
}//main()