-
Notifications
You must be signed in to change notification settings - Fork 0
/
new 1.c
84 lines (84 loc) · 907 Bytes
/
new 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
75
76
77
78
79
80
81
82
83
84
#include<stdio.h>
#include<string.h>
#define N strlen(g)
Void crc();
Void xor();
char g[20];
char text[100];
char code[100];
int len;
int main()
{
inti,flag=0;
printf("\nEntermsg in binary form: ");
scanf("%s",text);
printf("\nEnter Generator: ");
scanf("%s",g);
len=strlen(text);
for(i=len;i<len+N-1;i++)
{
text[i]='0';
}
crc();
for(i=len;i<len+N-1;i++)
{
text[i]=code[i-len];
}
printf("\nFinalCodeword: %s\n",text);
printf("\nEnter the coded word: ");
scanf("%s",text);
crc();
for(i=0;i<strlen(code);i++)
if(code[i]=='1')
{
flag=1;
break;
}
}
if(flag==1)
{
printf("\nERROR\n");
}
else
{
printf("\nNO ERROR\n");
}
return 0;
}
Void crc()
{
Int i,j;
for(i=0;i<N;i++)
{
code[i]=text[i];
}
do
{
if(code[0]=='1')
{
xor();
}
for(j=0;j<N-1;j++)
{
code[j]=code[j+1];
}
code[j]=text[i];
i++;
}
while(i<=len+N-1);
}
Void xor()
{
int i;
for(i=0;i<N;i++)
{
if(code[i]==g[i])
{
code[i]='0';
}
else
{
code[i]='1';
}
}
}