Skip to content

Commit c141881

Browse files
committed
version 1
0 parents  commit c141881

File tree

4 files changed

+574
-0
lines changed

4 files changed

+574
-0
lines changed

1.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The current shape of the North American continent (the present-day territory of the United States of America and Canada) was formed 25,000 years ago. At that time the great northern icecap flowed over the North American continent. This ice flow determined the size and drainage of the Great Lakes. They changed the direction of the Missouri River and carved the channel of the Hudson River. They created the northern part of the Central Agricultural Basin, which is one of the richest farming areas in the world.
2+
On the Atlantic shore of the United States, much of the northern coast is rocky. But the middle and southern Atlantic coasts rise gently from the sea. The Appalachians, which run almost parallel to the east coast, are old mountains with many coal rich valleys between them To the west of the Appalachians, lie plateaus built up over the centuries from bits of stone that were washed down from the mountains and then cut into small hills by streams. Beyond is the great Central Lowland which resembles the plains of Eastern Europe.
3+
North of the Central Lowland, extending for almost 1,600 kilometers, are the five Great Lakes, which the United States shares with Canada. The lakes are considered to contain about half of the world�s fresh water. West of the Central Lowland are the Great Plains. They are stopped by the Rocky Mountains. The Rockies are young mountains. They are the same age as the Alps in Europe.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Familiarization with the Hamming method of error-correcting coding, which allows to detect and automatically correct errors that occur during the transmission of information.

union_deheming.c

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <math.h>
4+
5+
int todec(int *byte);
6+
void invert(int *byte);
7+
void tobit(int x, int *byte);
8+
void kontrolbit(int *kod, int lengh);
9+
10+
int main()
11+
{
12+
FILE *f = fopen("C:/laba/2.txt", "rb");
13+
FILE *t = fopen("C:/laba/3.txt", "w+b");
14+
int byte[8];
15+
printf("coded file: C:/laba/2.txt\n");
16+
printf("file: C:/laba/3.txt\n\n");
17+
printf("select decoding length 8/12/16/32/64: ");
18+
int c;
19+
scanf("%d", &c);
20+
if(c == 8)
21+
{
22+
int x, kod[12], g = 0;
23+
while(fgetc(f) != EOF)
24+
{
25+
fseek(f, -1, SEEK_CUR);
26+
x = fgetc(f);
27+
tobit(x, byte);
28+
for(int i = 0; i < 8; i++)
29+
{
30+
if((i != 0)&&(i != 1))
31+
kod[g++] = byte[i];
32+
}
33+
if(g == 12)
34+
{
35+
kontrolbit(kod, 12);
36+
g = 0;
37+
for(int i = 0; i < 12; i++)
38+
{
39+
if((i+1 != 1)&&(i+1 != 2)&&(i+1 != 4)&&(i+1 != 8))
40+
{
41+
byte[g++] = kod[i];
42+
}
43+
}
44+
fputc(todec(byte), t);
45+
g = 0;
46+
}
47+
}
48+
}
49+
else if(c == 12)
50+
{
51+
int tmp[4], x, kod[17], g = 0, flag = 0, schet = 0;
52+
while(fgetc(f) != EOF)
53+
{
54+
fseek(f, -1, SEEK_CUR);
55+
x = fgetc(f);
56+
tobit(x, byte);
57+
kod[g] = byte[7];
58+
g++;
59+
if(g == 17)
60+
{
61+
g = 0;
62+
kontrolbit(kod, 17);
63+
g = 0;
64+
if(flag == 1) //костыль
65+
{
66+
for(int i = 0; i < 4; i++)
67+
{
68+
byte[g++] = tmp[i];
69+
}
70+
flag = 0;
71+
}
72+
for(int i = 0; i < 17; i++)
73+
{
74+
if((i+1 != 1)&&(i+1 != 2)&&(i+1 != 4)&&(i+1 != 8)&&(i+1 != 16)&&(i+1 != 32)&&(i+1 != 64))
75+
byte[g++] = kod[i];
76+
if(g == 8)
77+
{
78+
fputc(todec(byte), t);
79+
g = 0;
80+
if((flag == 0)&&(schet%2 == 0)) //костыль 2
81+
{
82+
for(int i = 12; i < 17; i++)
83+
{
84+
if(i+1 != 16)
85+
{
86+
tmp[g++] = kod[i];
87+
}
88+
}
89+
flag = 1;
90+
}
91+
g = 0;
92+
}
93+
}
94+
g = 0;
95+
}
96+
schet++; //костыль 3
97+
}
98+
}
99+
else if(c == 16)
100+
{
101+
int x, kod[21], g = 0;
102+
while(fgetc(f) != EOF)
103+
{
104+
fseek(f, -1, SEEK_CUR);
105+
x = fgetc(f);
106+
tobit(x, byte);
107+
for(int i = 0; i < 8; i++)
108+
{
109+
if(i != 0)
110+
kod[g++] = byte[i];
111+
}
112+
if(g == 21)
113+
{
114+
kontrolbit(kod, 21);
115+
g = 0;
116+
for(int i = 0; i < 21; i++)
117+
{
118+
if((i+1 != 1)&&(i+1 != 2)&&(i+1 != 4)&&(i+1 != 8)&&(i+1 != 16)&&(i+1 != 32)&&(i+1 != 64))
119+
byte[g++] = kod[i];
120+
if(g == 8)
121+
{
122+
fputc(todec(byte), t);
123+
g = 0;
124+
}
125+
}
126+
}
127+
}
128+
}
129+
else if(c == 32)
130+
{
131+
int x, kod[38], g = 0;
132+
while(fgetc(f) != EOF)
133+
{
134+
fseek(f, -1, SEEK_CUR);
135+
x = fgetc(f);
136+
tobit(x, byte);
137+
for(int i = 0; i < 8; i++)
138+
{
139+
if((i == 6)||(i == 7))
140+
kod[g++] = byte[i];
141+
}
142+
if(g == 38)
143+
{
144+
kontrolbit(kod, 38);
145+
g = 0;
146+
for(int i = 0; i < 38; i++)
147+
{
148+
if((i+1 != 1)&&(i+1 != 2)&&(i+1 != 4)&&(i+1 != 8)&&(i+1 != 16)&&(i+1 != 32)&&(i+1 != 64))
149+
byte[g++] = kod[i];
150+
if(g == 8)
151+
{
152+
fputc(todec(byte), t);
153+
g = 0;
154+
}
155+
}
156+
}
157+
}
158+
}
159+
else if(c == 64)
160+
{
161+
int x, kod[71], g = 0;
162+
while(fgetc(f) != EOF)
163+
{
164+
fseek(f, -1, SEEK_CUR);
165+
x = fgetc(f);
166+
tobit(x, byte);
167+
for(int i = 0; i < 8; i++)
168+
{
169+
if(i == 7)
170+
kod[g++] = byte[i];
171+
}
172+
if(g == 71)
173+
{
174+
kontrolbit(kod, 71);
175+
g = 0;
176+
for(int i = 0; i < 71; i++)
177+
{
178+
if((i+1 != 1)&&(i+1 != 2)&&(i+1 != 4)&&(i+1 != 8)&&(i+1 != 16)&&(i+1 != 32)&&(i+1 != 64))
179+
byte[g++] = kod[i];
180+
if(g == 8)
181+
{
182+
fputc(todec(byte), t);
183+
g = 0;
184+
}
185+
}
186+
}
187+
}
188+
}
189+
fclose(f);
190+
fclose(t);
191+
printf("COMPLETE!");
192+
getchar(); getchar();
193+
return 0;
194+
}
195+
196+
void kontrolbit(int *kod, int lengh)
197+
{
198+
int i = 0, summ = 0, errorpos = 0;
199+
while(i < lengh)
200+
{
201+
if((i+1 == 1)||(i+1 == 2)||(i+1 == 4)||(i+1 == 8)||(i+1 == 16)||(i+1 == 32)||(i+1 == 64))
202+
{
203+
int start = i;
204+
while(start < lengh)
205+
{
206+
for(int g = 0; g < i + 1; g++)
207+
{
208+
if((start+g != i)&&(start+g < lengh))
209+
summ = summ + kod[start+g];
210+
}
211+
start = start + i + i + 2;
212+
}
213+
if(kod[i] != summ%2)
214+
{
215+
errorpos = errorpos + i;
216+
}
217+
summ = 0;
218+
}
219+
i++;
220+
}
221+
if(errorpos != 0)
222+
{
223+
if(kod[errorpos] == 0)
224+
kod[errorpos] = 1;
225+
else
226+
kod[errorpos] = 0;
227+
}
228+
}
229+
230+
void tobit(int x, int *byte)
231+
{
232+
for(int i = 0; i < 8; i++)
233+
{
234+
byte[i] = x%2;
235+
x = x/2;
236+
}
237+
invert(byte);
238+
}
239+
240+
void invert(int *byte)
241+
{
242+
int tmp[8], g = 0;
243+
for(int i = 7; i > -1; i--)
244+
tmp[g++] = byte[i];
245+
for(int i = 0; i < 8; i++)
246+
byte[i] = tmp[i];
247+
}
248+
249+
int todec(int *byte)
250+
{
251+
int x = 0, st = 7;
252+
for(int i = 0; i < 8; i++)
253+
{
254+
x = x + byte[i]*pow(2, st);
255+
st--;
256+
}
257+
return x;
258+
}

0 commit comments

Comments
 (0)