以下为LLL算法的实现过程:(matlab代码)
本人在课程设计中完成以下工作
function [Y,square_length_Y_Y, Y_Y_coefficient] = LLL_exchange( k , Y , square_length_Y_Y , Y_Y_coefficient )
%UNTITLED2 此处显示有关此函数的摘要
% 此处显示详细说明
disp('-----LLL_exchange---------start---------------------')
k
Y
% Y_Y_coefficient
% square_length_Y_Y
z = Y(k-1,:);
Y(k-1,:) = Y(k,:);
Y(k,:) = z;
v = Y_Y_coefficient(k,k-1);
siple = square_length_Y_Y(1,k) + v*v* square_length_Y_Y(1,k-1);
Y_Y_coefficient(k,k-1) = v * square_length_Y_Y(1,k-1) / siple;
square_length_Y_Y(1,k) = square_length_Y_Y(1,k) * square_length_Y_Y(1,k-1) / siple;
square_length_Y_Y(1,k-1) = siple;
%(4)
for j=1:k-2
t = Y_Y_coefficient(k-1,j);
Y_Y_coefficient(k-1,j) = Y_Y_coefficient(k,j);
Y_Y_coefficient(k,j) = t;
end
%(5)
[n n] = size(square_length_Y_Y);
for i= k+1:n
E=Y_Y_coefficient(i,k) ;
Y_Y_coefficient(i,k) = Y_Y_coefficient(i,k-1) - v * Y_Y_coefficient(i,k);
Y_Y_coefficient(i,k-1) = Y_Y_coefficient(k,k-1) * Y_Y_coefficient(i,k) + E;
end
disp('-----LLL_exchange---------end---------------------')
end
function [Y,Y_Y_coefficient] = LLL_reduced( k ,l ,Y , Y_Y_coefficient )
%UNTITLED3 此处显示有关此函数的摘要
% 此处显示详细说明
disp('LLL_reduced--------start----------')
k
l
Y
% Y_Y_coefficient
if abs( Y_Y_coefficient(k,l) ) > 0.5
Y(k,:) = Y(k,:) - round( Y_Y_coefficient(k,l) ) * Y(l,:);
for j=1:l-1
Y_Y_coefficient(k,j) = Y_Y_coefficient(k,j) - round( Y_Y_coefficient(k,l) ) * Y_Y_coefficient(l,j) ;
end
Y_Y_coefficient(k,l) = Y_Y_coefficient(k,l) - round( Y_Y_coefficient(k,l) );
end
disp('LLL_reduced--------end----------')
end
clc
clear
%Y=[-2 7 7 -5; 3 -2 6 -1;2 -8 -9 -7;8 -9 6 -4];
Y = [10305608 , -597165 , 45361210 , 39600006 , 12036060
-71672908 , 4156981 , -315467761, -275401230, -83709146
-46304904 , 2685749 , -203811282, -177925680, -54081387
-68449642 , 3969419 , -301282167, -263017213, -79944525
-46169690 , 2677840 , -203215644, -177405867, -53923216 ]
%Y = [ 19, 2 , 32, 46, 3 , 33,
% 15, 42, 11, 0 , 3 , 24,
% 43, 15, 0 , 24, 4 , 16,
% 20, 44, 44, 0 , 18, 15,
% 0 , 48, 35, 16, 31, 31,
% 48, 33, 32, 9 , 1 , 29
% ]
[n n] = size(Y) ;
Y_Y = zeros(n,n);
Y_Y_coefficient = zeros(n,n);
square_length_Y_Y = zeros(1,n);
format rat
for i=1:n
Y_Y(i,:) = Y (i,:);
Y_Y_coefficient(i,i) = 1;
for j=1:i-1
Y_Y_coefficient(i,j) = dot( Y(i,:) , Y_Y(j,:) ) / square_length_Y_Y(1,j);
Y_Y(i,:) = Y_Y(i,:) - Y_Y_coefficient(i,j) * Y_Y(j,:);
end
square_length_Y_Y(1,i) = dot( Y_Y(i,:) , Y_Y(i,:) );
end
%---------------------Y_Y_coefficient
%---------------------square_length_Y_Y
disp('初次设置k=2----------------------------')
k=2
while k<=n
[Y,Y_Y_coefficient] = LLL_reduced(k,k-1,Y,Y_Y_coefficient);
if square_length_Y_Y(1,k) >= (0.75 - Y_Y_coefficient(k,k-1) ^ 2 ) * square_length_Y_Y(1,k-1)
for l=k-2:-1:1
[Y, Y_Y_coefficient] = LLL_reduced(k,l,Y,Y_Y_coefficient);
end
k=k+1;
else
[Y,square_length_Y_Y, Y_Y_coefficient] = LLL_exchange( k , Y , square_length_Y_Y , Y_Y_coefficient );
if k>2
k=k-1 ;
end
end
Y
end