Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Họ và Tên SV:Võ Văn Thành

Lớp:21DT1
MSSV:106210019

BÀI 1: KỸ THUẬT MÃ HÓA KÊNH


Bài 1:

 Code:
a = 'Faculty of Electronic and Telecommunication';

c = '';
for i = 1:length(a)
ascii_bin = dec2bin(double(a(i)), 7);

if ismember(i, [1, 2, 4, 3, 3, 5, 7, 1, 6, 1, 2])


ascii_bin(1) = '0';
end

c = strcat(c, ascii_bin);
end

decoded_text = '';
for j = 1:7:length(c)
binary_char = c(j:j+6);
ascii_char = bin2dec(binary_char);
decoded_text = [decoded_text, char(ascii_char)];
end

disp('Chuoi sau khi mã hóa:');


disp(c);
disp('Chuoi sau khi giải mã:');
disp(decoded_text);

 Kết quả

 Nhận xét:
Mặc dù mã ASCII không có khả năng phát hiện, cũng không sửa được các lỗi. Nếu một bit trong
dữ liệu ASCII bị mất hoặc bị thay đổi trong quá trình truyền, các thiết bị hoặc phần mềm không
thể phát hiện ra lỗi này và sẽ giải mã dữ liệu bị lỗi một cách sai lệch.

Bài 2:
 Code:
clc;
close all;
clear all;

T='Electronic';
m = dec2bin(T, 7)-'0';
x=[1 0 0 0
1 0 1 1
1 0 1 1
0 0 1 1
0 0 1 0
1 1 1 0
0 0 1 1
1 1 1 0
1 0 0 1
1 1 0 0
1 0 1 1
0 1 1 1
1 1 1 0
1 1 1 0
1 1 0 1
0 0 1 1
1 0 0 0
1 1 0 0];
G=[1 0 0 0 1 1 1
0 1 0 0 0 1 1
0 0 1 0 1 0 1
0 0 0 1 1 1 0];
a1=x(1,:)*G;
a1=mod(a1,2);
a2=x(2,:)*G;
a2=mod(a2,2);
a3=x(3,:)*G;
a3=mod(a3,2);
a4=x(4,:)*G;
a4=mod(a4,2);
a5=x(5,:)*G;
a5=mod(a5,2);
a6=x(6,:)*G;
a6=mod(a6,2);
a7=x(7,:)*G;
a7=mod(a7,2);
a8=x(8,:)*G;
a8=mod(a8,2);
a9=x(9,:)*G;
a9=mod(a9,2);
a10=x(10,:)*G;
a10=mod(a10,2);
a11=x(11,:)*G;
a11=mod(a11,2);
a12=x(12,:)*G;
a12=mod(a12,2);
a13=x(13,:)*G;
a13=mod(a13,2);
a14=x(14,:)*G;
a14=mod(a14,2);
a15=x(15,:)*G;
a15=mod(a15,2);
a16=x(16,:)*G;
a16=mod(a16,2);
a17=x(17,:)*G;
a17=mod(a17,2);
a18=x(18,:)*G;
a18=mod(a18,2);
mahoaASCII=[a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18];
mahoa_4_7 = num2str (mahoaASCII);
clc;
close all;
clear all;

T='Electronic';
G=[1 0 0 0 1 1 1
0 1 0 0 0 1 1
0 0 1 0 1 0 1
0 0 0 1 1 1 0];

x=dec2bin(T)-'0';
x1=x(1,:);
m_ERROR=[1 0 0 0
1 0 1 1
1 0 1 1
0 0 1 1
0 0 1 0
1 1 1 0
0 0 1 1
1 1 1 0
1 0 0 1
1 1 0 0
1 0 1 1
0 1 1 1
1 1 1 0
1 1 1 0
1 1 0 1
0 0 1 1
1 0 0 0
1 1 0 0];
H=[1 0 1 1 1 0 0
1 1 0 1 0 1 0
1 1 1 0 0 0 1];
e=[zeros(1,7)
eye(7)];
s=e*H';
r=m_ERROR*G;
r1=m_ERROR*G;
r1=mod(r1,2);
r1(1,1)=~r1(1,1);
r1(2,3)=~r1(2,3);
r11=r1(1,:);
r77=r1(2,:);
s1=r11*H';
s1=mod(s1,2);
s7=r77*H';
s7=mod(s7,2);
e_loi_1=' ';
r_sualoi_1=' ';
e_loi_7=' ';
r_sualoi_7=' ';
for i=1:8
if s1==s(i,:)
disp(['chu E loi vi tri thu ' num2str(i-1) ''])
e_loi_1=e(i,:);
e_loi_1=mod(e_loi_1,2);
else
disp('khong phat hien duoc loi')

end
if s7==s(i,:)
disp(['chu l loi vi tri thu ' num2str(i-1) ''])
e_loi_7=e(i,:);
e_loi_7=mod(e_loi_7,2);
else
disp('khong phat hien duoc loi')

end
end

r_sualoi_1=r11+e_loi_1;
r_sualoi_7=r77+e_loi_7;
r111=[r_sualoi_1(1:4) r_sualoi_7(1:3); r_sualoi_7(4) x(2,2:7); x(3:10,:)];

kytu_saukhisualoi_1_7=char(bin2dec(num2str(r111)));
ky_tu_sau_khi_sua_loi= kytu_saukhisualoi_1_7';
fprintf('ki tu sau khi sua loi: ');
fprintf(ky_tu_sau_khi_sua_loi);

fprintf('ki tu ban dau: ');


fprintf('Electronic');

 Kết quả:
 Nhận xét

_ Mã (4,7) có khả năng phát hiện lỗi. Tuy nhiên nó chỉ phát hiện được tối đa 1 bit,
lỗi nhiều hơn sẽ không được

Bài 3:
 Code:
clc;
close all;
clear all;

T='Electronic';
x = dec2bin(T, 7)-'0';
G=[1 0 0 0 0 0 0 1 1 1 1
0 1 0 0 0 0 0 0 1 1 0
0 0 1 0 0 0 0 1 0 1 0
0 0 0 1 0 0 0 1 1 0 0
0 0 0 0 1 0 0 1 1 0 1
0 0 0 0 0 1 0 0 0 1 1
0 0 0 0 0 0 1 0 0 0 1];
a1=x(1,:)*G;
a1=mod(a1,2);
a2=x(2,:)*G;
a2=mod(a2,2);
a3=x(3,:)*G;
a3=mod(a3,2);
a4=x(4,:)*G;
a4=mod(a4,2);
a5=x(5,:)*G;
a5=mod(a5,2);
a6=x(6,:)*G;
a6=mod(a6,2);
a7=x(7,:)*G;
a7=mod(a7,2);
a8=x(8,:)*G;
a8=mod(a8,2);
a9=x(9,:)*G;
a9=mod(a9,2);
a10=x(10,:)*G;
a10=mod(a10,2);
mahoaASCII=[a1 a2 a3 a4 a5 a6 a7 a8 a9 a10];
mahoa_7_11 = num2str (mahoaASCII);
clc;
close all;
clear all;

T='Electronic';
G=[1 0 0 0 0 0 0 0 1 1 1
0 1 0 0 0 0 0 0 1 1 0
0 0 1 0 0 0 0 1 0 1 0
0 0 0 1 0 0 0 1 1 0 0
0 0 0 0 1 0 0 1 1 0 1
0 0 0 0 0 1 0 0 0 1 1
0 0 0 0 0 0 1 1 0 0 1];

m_ERROR=dec2bin(T)-'0' ;
H=[0 0 1 1 1 0 1 1 0 0 0
1 1 0 1 1 0 0 0 1 0 0
1 1 1 0 0 1 0 0 0 1 0
1 0 0 0 1 1 1 0 0 0 1];
e=[zeros(1,11)
eye(11)];
s=e*H';
c=m_ERROR*G;
r1_7=m_ERROR*G;
r1_7=mod(r1_7,2);
r1_7(1,1)=~r1_7(1,1);
r1_7(1,7)=~r1_7(1,7);
r11_77=r1_7(1,:);
s1_7=r11_77*H';
s1_7=mod(s1_7,2);
e_loi_1_7=' ';
r_sualoi_1_7=' ';
for i=1:12
if s1_7==s(i,:)
disp(['s1 va s7 loi vi tri thu ' num2str(i-1) ''])
e_loi_1_7=e(i,:);
e_loi_1_7=mod(e_loi_1_7,2);
else
disp('khong phat hien duoc loi')

end
end
r_sualoi_1_7=r11_77+e_loi_1_7;
r_sualoi_1_7=mod(r_sualoi_1_7,2);

a=[r_sualoi_1_7(1:7); m_ERROR(2:10,:)];
kytu_saukhisualoi_1_7=char(bin2dec(num2str(a)));
ky_tu_sau_khi_sua_loi= kytu_saukhisualoi_1_7';
fprintf('ki tu sau khi sua loi: ');
fprintf(ky_tu_sau_khi_sua_loi);
fprintf('ki tu ban dau: ');
fprintf('Electronic');

 Kết quả:

 Nhận xét:
_ Khả năng phát hiện lỗi: Mã (4,7) và mã (7,11) đều có khả năng phát hiện lỗi
tuy nhiên cả 2 đều chỉ phát hiện được tối đa 1 bit lỗi nhiều hơn sẽ không được;
mã (7,11) thì có khả năng phát hiện lỗi tốt hơn do độ dài của mã (7,11) lớn hơn.

You might also like