具体秘密共享的流程可以参考下面这个链接的内容:https://blog.csdn.net/Matrix_element/article/details/117357359
main1.m
加法方案的主函数:确认门限(代码里(5,3))以及对应的两个多项式(代码对应的多项式是y1 = 2 * x ^ 2 - 3 * x + 4, y2 = x ^ 2 + 5 x - 6,所以通过多项式分发给每个人两个值,最后通过3个人的子秘密和恢复出4 + -6 = - 2)-> 给每个人分发子秘密值 -> 通过3个人的子秘密值和使用拉格朗日恢复出-2(两个多项式的常数项和)
%%%加法方案
%%分发
% 首先确定方案门限值
a = [5,3];
% 输入多项式的参数,生成每个人相应的密钥
% coef1 = [2,-3,4;
% 1,5,-6];%自己定义多项式系数矩阵
coef1 = ceil(rand(2,a(2))*10)%随机生成多项式系数矩阵
s = Sharing(a, coef1);
add_s = sum(s,2);
%%恢复
%P = [1,3,5];
P = [1,add_s(1);
3,add_s(3);
5,add_s(5)];
y = Recover(a,P)
% %恢复加法秘密值
% ab=0;
% ab = add_s(1) * ( (0-P(2)) * (0-P(3)) ) / ( (P(1)-P(2)) * (P(1)-P(3)) ) + ...
% add_s(3) * ( (0-P(1)) * (0-P(3)) ) / ( (P(2)-P(1)) * (P(2)-P(3)) ) + ...
% add_s(5) * ( (0-P(1)) * (0-P(2)) ) / ( (P(3)-P(1)) * (P(3)-P(2)) )
% %恢复多项式
% syms x;
% y = add_s(1) * ( (x-P(2)) * (x-P(3)) ) / ( (P(1)-P(2)) * (P(1)-P(3)) ) + ...
% add_s(3) * ( (x-P(1)) * (x-P(3)) ) / ( (P(2)-P(1)) * (P(2)-P(3)) ) + ...
% add_s(5) * ( (x-P(1)) * (x-P(2)) ) / ( (P(3)-P(1)) * (P(3)-P(2)) )
% y = expand(y)
main2.m
乘法方案主函数:确认门限以及对应的两个多项式-> 给每个分发子秘密值 -> 每个人再通过分发的子秘密值乘积为常数项生成自己的多项式->用自己的多项式给每个人再次进行分发(代码里的C矩阵)->计算lamda向量(这个每个人都可以计算) ->根据计算的lamda向量和每个人手里拥有的向量求每个人的最终拥有的子秘密值-> 通过3个人的子秘密值和使用拉格朗日恢复出-24(两个多项式的常数项积)
%%%乘法
%%一、首先确定方案门限值
a = [5,3];
% 输入多项式的参数,生成每个人相应的密钥
%coef1 = ceil(rand(2,a(2))*10)%随机生成矩阵值
coef1 = [2,-3,4;
1,5,-6];%或者自定义矩阵
s = Sharing(a, coef1);
mul_s = prod(s,2);
%%二、每个P根据自己得到的d生成自己的n-1次多项式,并分发给每个参与者
%coef_H = [ceil(rand(a(1),a(2)-1)*100),mul_s]%随机生成多项式系数矩阵
coef_H = [1,-1,mul_s(1);
1,-10,mul_s(2);
1,-100,mul_s(3);
1,-200,mul_s(4);
1,-300,mul_s(5)];%或者自定义多项式系数矩阵
%计算C矩阵
CMatrix = CalculateCMatrix1(a,coef_H)
%%三、计算λ矩阵,每个人Pi根据自己得到的5个cji(1 <= j <= 5)
lamda = zeros(1,a(1));
M = zeros(a(1),a(1));
m = [1:1:a(1)]';
for i = 1:a(1)
M(:,i) = m.^(i-1)
end
% M = [1,1,1,1,1;
% 1,2,2^2,2^3,2^4;
% 1,3,3^2,3^3,3^4;
% 1,4,4^2,4^3,4^4;
% 1,5,5^2,5^3,5^4];
lamda = [1,0,0,0,0] * inv(M);
%每个人根据自己得到的Cji计算C值
C = lamda * CMatrix;
%%四、进行恢复(比如满足1,3,5人),根据这几个人计算得到的C值进行恢复
P = [1,3,5];
ab=0;
ab = C(P(1)) * ( (0-P(2)) * (0-P(3)) ) / ( (P(1)-P(2)) * (P(1)-P(3)) ) + ...
C(P(2)) * ( (0-P(1)) * (0-P(3)) ) / ( (P(2)-P(1)) * (P(2)-P(3)) ) + ...
C(P(3)) * ( (0-P(1)) * (0-P(2)) ) / ( (P(3)-P(1)) * (P(3)-P(2)) )
%恢复多项式
syms x;
y = C(P(1)) * ( (x-P(2)) * (x-P(3)) ) / ( (P(1)-P(2)) * (P(1)-P(3)) ) + ...
C(P(2)) * ( (x-P(1)) * (x-P(3)) ) / ( (P(2)-P(1)) * (P(2)-P(3)) ) + ...
C(P(3)) * ( (x-P(1)) * (x-P(2)) ) / ( (P(3)-P(1)) * (P(3)-P(2)) );
y = expand(y)
Sharing.m
function [s] = Sharing(a,b)
%计算分发给每个人的密钥
poly_num = size(b,1);%多项式个数
s = zeros(a(1),poly_num);
max = size(b,2);%每个多项式项数
for x = 1:a(1)
for i = 1:poly_num
for j = 0:max-1
s(x,i) = s(x,i) + b(i,max-j) * x^j;
end
% s(x,1) = b(1,1) * x^2 + b(1,2) * x + b(1,3);
% s(x,2) = b(2,1) * x^2 + b(2,2) * x + b(2,3);
end
end
CalculateCMatrix.m
计算c矩阵方法1
function [s] = CalculateCMatrix(a,coef_H)
% s = zeros(a(1),a(1));
% max = size(coef_H,2);
% for i = 1:a(1)
% for j = 1:a(1)
% for t = 0:max-1
% s(i,j) = s(i,j) + coef_H(i,max-t) * j^t;
% end
% end
% end
M = zeros(a(2),a(1));
m = [1:1:a(1)];
for i = a(2):-1:1
M(i,:) = m.^(a(2)-i);
end
s = coef_H * M;
end
方法2:
function [C] = CalculateCMatrix(a,coef_H)
C = zeros(a(1),a(1));
for i = 1:a(1)
for j = 1:a(1)
C(i,j) = coef_H(i,1) * j^2 + coef_H(i,2) * j + coef_H(i,3);
end
end
end
Recover.m
朗格朗日恢复
function [y] = Recover(a,P)
num = size(P,1);
y = 0;
if num<a(2)
tip = "人数不足恢复"
else
syms x;
for i = 1:num
s = P(i,2);
for j = 1:num
if(i ~= j)
s = s * (x - P(j,1))/ ( P(i,1) - P(j,1) );
end
end
y = y + s;
end
% y = add_s(1) * ( (x-P(2)) * (x-P(3)) ) / ( (P(1)-P(2)) * (P(1)-P(3)) ) + ...
% add_s(3) * ( (x-P(1)) * (x-P(3)) ) / ( (P(2)-P(1)) * (P(2)-P(3)) ) + ...
% add_s(5) * ( (x-P(1)) * (x-P(2)) ) / ( (P(3)-P(1)) * (P(3)-P(2)) )
end
y = expand(y);
end
以上函数可以将整个流程进行实现。接下来使用matlab appdesigner调用上面函数进行可视化实现,整个流程更加清晰明了。
classdef SharingSecret < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ShamirLabel matlab.ui.control.Label
Panel matlab.ui.container.Panel
Button matlab.ui.control.Button
nSpinnerLabel matlab.ui.control.Label
nSpinner matlab.ui.control.Spinner
mSpinnerLabel matlab.ui.control.Label
mSpinner matlab.ui.control.Spinner
nmEditFieldLabel matlab.ui.control.Label
nmEditField matlab.ui.control.EditField
Panel_2 matlab.ui.container.Panel
ButtonGroup_2 matlab.ui.container.ButtonGroup
Button_4 matlab.ui.control.RadioButton
Button_5 matlab.ui.control.RadioButton
UITable matlab.ui.control.Table
Button_6 matlab.ui.control.Button
UITable2 matlab.ui.control.Table
Panel_3 matlab.ui.container.Panel
Label_4 matlab.ui.control.Label
UITable2_3 matlab.ui.control.Table
UITable2_4 matlab.ui.control.Table
CLabel matlab.ui.control.Label
CLabel_2 matlab.ui.control.Label
UITable2_5 matlab.ui.control.Table
ButtonGroup_3 matlab.ui.container.ButtonGroup
Button_9 matlab.ui.control.RadioButton
Button_10 matlab.ui.control.RadioButton
Button_11 matlab.ui.control.Button
Button_12 matlab.ui.control.Button
Panel_4 matlab.ui.container.Panel
TextArea matlab.ui.control.TextArea
Button_8 matlab.ui.control.Button
Button_7 matlab.ui.control.Button
EditFieldLabel matlab.ui.control.Label
iEditField2 matlab.ui.control.NumericEditField
iEditFieldLabel matlab.ui.control.Label
iEditField matlab.ui.control.NumericEditField
UITable3 matlab.ui.control.Table
Button_14 matlab.ui.control.Button
Button_13 matlab.ui.control.Button
end
properties (Access = private)
a;%门限
flag_trapdoor = 0; %门限是否设置成功
flag_share = 0; %分发是否成功
s;%给每个人分发的秘密值
s_add;%加法方案分配给每个人的值求和
s_mul;%乘法方案分配给每个人的值求积
end
methods (Access = private)
% Button pushed function: Button
function Trapdoor(app, event)
temp1 = app.nSpinner.Value;
temp2 = app.mSpinner.Value;
app.a = [temp1,temp2];
if temp2 > temp1
msgbox("解密人数>总人数,重新输入","提示");
elseif temp2 <= 1
msgbox("解密人数需大于1","提示");
else
app.nmEditField.Value = "(" + app.a(1) + "," + app.a(2) + ")";
app.flag_trapdoor = 1;
temp = char();
for i = 1:app.a(1)
temp = [temp;sprintf('第%3d个人',i)];
end
app.UITable2.ColumnName = temp;
app.UITable2_3.ColumnName = temp;
app.UITable2_4.ColumnName = temp;
app.UITable2_5.ColumnName = temp;
% c = char();
% for i = 1:app.a(2)
% if i==1
% c = [' 常数项 ';c];
% else
% c = [sprintf('%3d次项系数 ',i-1);c];
% end
%
% end
% app.UITable2_3.RowName = c;
%app.ButtonGroup_2.SelectedObject.Value = 0;
end
end
% Callback function: ButtonGroup_2, UITable2
function ButtonGroup_2SelectionChanged(app, event)
selectedButton = app.ButtonGroup_2.SelectedObject;
if app.flag_trapdoor == 0
msgbox("请先输入门限值","提示");
else
c = char();
for i = 1:app.a(2)
if i==1
c = [' 常数项 ';c];
else
c = [sprintf('%3d次项系数 ',i-1);c];
end
end
app.UITable.RowName = c;
b = zeros(app.a(2),2);
app.UITable.Data = b;
switch selectedButton.Text
case "自定义多项式系数"
%msgbox('1');
app.UITable.Data = b;
case "随机生成"
%msgbox('2');
%app.UITable.RowName = c;
%app.UITable.Data = ceil(rand(2,app.a(2))*10)';
app.UITable.Data = randi([-10 10],app.a(2),2);
app.flag_share = 1;
end
end
end
% Cell edit callback: UITable
function UITableCellEdit(app, event)
end
% Button pushed function: Button_6
function Button_6Pushed(app, event)
app.s = Sharing(app.a, app.UITable.Data');
app.UITable2.Data = app.s';
app.s
app.s_add = sum(app.s, 2);
app.s_mul = prod(app.s, 2);
end
% Button pushed function: Button_7
function Button_7Pushed(app, event)
%t;
temp = [app.iEditField.Value,app.iEditField2.Value];
app.UITable3.Data = [app.UITable3.Data;temp];
end
% Button pushed function: Button_8
function Button_8Pushed(app, event)
if size(app.UITable3.Data,1)<app.a(2)
msgbox("不足恢复人数","提示");
else
P = app.UITable3.Data(1:app.a(2),:);%取前m行进行计算
y = Recover(app.a,P);
app.TextArea.Value = string(y);
end
end
% Selection changed function: ButtonGroup_3
function ButtonGroup_3SelectionChanged(app, event)
selectedButton = app.ButtonGroup_3.SelectedObject;
if app.flag_share ==0
msgbox("请先完成乘法密钥分发","提示");
else
c = char();
for i = 1:app.a(2)
if i==1
c = [' 常数项 ';c];
else
c = [sprintf('%3d次项系数 ',i-1);c];
end
end
b = zeros(app.a(2),app.a(1));
app.UITable2_3.Data = b;
switch selectedButton.Text
case "自定义多项式系数"
%msgbox('1');
app.UITable2_3.ColumnEditable = true;
app.UITable2_3.Data = b;
case "随机生成"
%msgbox('2');
app.UITable2_3.RowName = c;
% t = ceil(rand(app.a(1),app.a(2)-1)*10)'
% t = app.s
%app.UITable2_3.Data = [ceil(rand(app.a(1),app.a(2)-1)*10)';app.s_mul'];
app.UITable2_3.Data = [randi([-100 100],app.a(2)-1,app.a(1));app.s_mul'];
end
end
end
% Button pushed function: Button_11
function Button_11Pushed(app, event)
CMatrix = CalculateCMatrix(app.a,app.UITable2_3.Data')
app.UITable2_4.Data = CMatrix;
end
% Button pushed function: Button_12
function Button_12Pushed(app, event)
%lamda = zeros(1,a(1));
M = zeros(app.a(1),app.a(1));
m = [1:1:app.a(1)]';
for i = 1:app.a(1)
M(:,i) = m.^(i-1)
end
desMatrix = zeros(1,app.a(1));
desMatrix(1) = 1;
lamda = desMatrix * inv(M);
%每个人根据自己得到的Cji计算C值
C = lamda * app.UITable2_4.Data;
app.UITable2_5.Data = C;
end
% Button pushed function: Button_13
function Button_13Pushed(app, event)
app.UITable.Data = [];
app.UITable2.Data = [];
app.UITable2_3.Data = [];
app.UITable2_4.Data = [];
app.UITable2_5.Data = [];
app.UITable3.Data = [];
app.TextArea.Value = "";
app.iEditField.Value= 0;
app.iEditField2.Value= 0;
app.nmEditField.Value = '';
app.nSpinner.Value = 0;
app.mSpinner.Value = 0;
end
% Button pushed function: Button_14
function Button_14Pushed(app, event)
app.UITable3.Data = [];
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Color = [0.9412 0.9412 0.9412];
app.UIFigure.Position = [100 100 640 734];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.Resize = 'off';
% Create ShamirLabel
app.ShamirLabel = uilabel(app.UIFigure);
app.ShamirLabel.BackgroundColor = [0.302 0.749 0.9294];
app.ShamirLabel.HorizontalAlignment = 'center';
app.ShamirLabel.FontName = '微软雅黑';
app.ShamirLabel.FontSize = 20;
app.ShamirLabel.FontWeight = 'bold';
app.ShamirLabel.Position = [1 706 640 29];
app.ShamirLabel.Text = '隐私计算-Shamir秘密共享方案';
% Create Panel
app.Panel = uipanel(app.UIFigure);
app.Panel.BorderType = 'none';
app.Panel.TitlePosition = 'centertop';
app.Panel.Title = '确认门限方案';
app.Panel.BackgroundColor = [1 1 0.9412];
app.Panel.FontWeight = 'bold';
app.Panel.FontSize = 16;
app.Panel.Position = [1 625 640 82];
% Create Button
app.Button = uibutton(app.Panel, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @Trapdoor, true);
app.Button.Position = [365 18 100 25];
app.Button.Text = '确定';
% Create nSpinnerLabel
app.nSpinnerLabel = uilabel(app.Panel);
app.nSpinnerLabel.HorizontalAlignment = 'right';
app.nSpinnerLabel.Position = [4 19 68 22];
app.nSpinnerLabel.Text = '总人数(n):';
% Create nSpinner
app.nSpinner = uispinner(app.Panel);
app.nSpinner.Limits = [0 1000];
app.nSpinner.ValueDisplayFormat = '%.0f';
app.nSpinner.HorizontalAlignment = 'center';
app.nSpinner.Position = [71 19 83 22];
% Create mSpinnerLabel
app.mSpinnerLabel = uilabel(app.Panel);
app.mSpinnerLabel.HorizontalAlignment = 'right';
app.mSpinnerLabel.Position = [175 19 83 22];
app.mSpinnerLabel.Text = '解密人数(m):';
% Create mSpinner
app.mSpinner = uispinner(app.Panel);
app.mSpinner.Limits = [0 1000];
app.mSpinner.ValueDisplayFormat = '%.0f';
app.mSpinner.HorizontalAlignment = 'center';
app.mSpinner.Position = [257 19 80 22];
% Create nmEditFieldLabel
app.nmEditFieldLabel = uilabel(app.Panel);
app.nmEditFieldLabel.HorizontalAlignment = 'right';
app.nmEditFieldLabel.Position = [485 19 69 22];
app.nmEditFieldLabel.Text = '门限(n,m):';
% Create nmEditField
app.nmEditField = uieditfield(app.Panel, 'text');
app.nmEditField.Editable = 'off';
app.nmEditField.HorizontalAlignment = 'center';
app.nmEditField.Position = [553 19 74 22];
% Create Panel_2
app.Panel_2 = uipanel(app.UIFigure);
app.Panel_2.TitlePosition = 'centertop';
app.Panel_2.Title = '加法乘法方案子秘密值分发';
app.Panel_2.BackgroundColor = [0.9608 1 0.9804];
app.Panel_2.FontWeight = 'bold';
app.Panel_2.FontSize = 16;
app.Panel_2.Position = [1 422 640 204];
% Create ButtonGroup_2
app.ButtonGroup_2 = uibuttongroup(app.Panel_2);
app.ButtonGroup_2.SelectionChangedFcn = createCallbackFcn(app, @ButtonGroup_2SelectionChanged, true);
app.ButtonGroup_2.Position = [8 133 292 30];
% Create Button_4
app.Button_4 = uiradiobutton(app.ButtonGroup_2);
app.Button_4.Text = '自定义多项式系数';
app.Button_4.Position = [11 3 118 22];
app.Button_4.Value = true;
% Create Button_5
app.Button_5 = uiradiobutton(app.ButtonGroup_2);
app.Button_5.Text = '随机生成';
app.Button_5.Position = [198 4 70 22];
% Create UITable
app.UITable = uitable(app.Panel_2);
app.UITable.ColumnName = {'第一个多项式参数'; '第二个多项式参数'};
app.UITable.RowName = {};
app.UITable.ColumnEditable = true;
app.UITable.CellEditCallback = createCallbackFcn(app, @UITableCellEdit, true);
app.UITable.Position = [8 13 292 114];
% Create Button_6
app.Button_6 = uibutton(app.Panel_2, 'push');
app.Button_6.ButtonPushedFcn = createCallbackFcn(app, @Button_6Pushed, true);
app.Button_6.Position = [517 137 100 26];
app.Button_6.Text = '分发子秘密值';
% Create UITable2
app.UITable2 = uitable(app.Panel_2);
app.UITable2.ColumnName = '';
app.UITable2.RowName = {};
app.UITable2.CellEditCallback = createCallbackFcn(app, @ButtonGroup_2SelectionChanged, true);
app.UITable2.Position = [325 13 292 114];
% Create Panel_3
app.Panel_3 = uipanel(app.UIFigure);
app.Panel_3.TitlePosition = 'centertop';
app.Panel_3.Title = '乘法方案再分发';
app.Panel_3.BackgroundColor = [0.9412 1 0.9412];
app.Panel_3.FontWeight = 'bold';
app.Panel_3.FontSize = 16;
app.Panel_3.Position = [1 176 640 247];
% Create Label_4
app.Label_4 = uilabel(app.Panel_3);
app.Label_4.HorizontalAlignment = 'center';
app.Label_4.Position = [13 197 113 22];
app.Label_4.Text = '再分发多项式系数:';
% Create UITable2_3
app.UITable2_3 = uitable(app.Panel_3);
app.UITable2_3.ColumnName = '';
app.UITable2_3.RowName = {};
app.UITable2_3.Position = [10 69 292 96];
% Create UITable2_4
app.UITable2_4 = uitable(app.Panel_3);
app.UITable2_4.ColumnName = '';
app.UITable2_4.RowName = {};
app.UITable2_4.Position = [325 70 292 124];
% Create CLabel
app.CLabel = uilabel(app.Panel_3);
app.CLabel.HorizontalAlignment = 'center';
app.CLabel.Position = [325 197 38 22];
app.CLabel.Text = 'C矩阵';
% Create CLabel_2
app.CLabel_2 = uilabel(app.Panel_3);
app.CLabel_2.HorizontalAlignment = 'center';
app.CLabel_2.Position = [3 34 142 22];
app.CLabel_2.Text = '每人计算的C值(子秘密值)';
% Create UITable2_5
app.UITable2_5 = uitable(app.Panel_3);
app.UITable2_5.ColumnName = '';
app.UITable2_5.RowName = {};
app.UITable2_5.Position = [143 7 474 49];
% Create ButtonGroup_3
app.ButtonGroup_3 = uibuttongroup(app.Panel_3);
app.ButtonGroup_3.SelectionChangedFcn = createCallbackFcn(app, @ButtonGroup_3SelectionChanged, true);
app.ButtonGroup_3.Position = [10 164 292 30];
% Create Button_9
app.Button_9 = uiradiobutton(app.ButtonGroup_3);
app.Button_9.Text = '自定义多项式系数';
app.Button_9.Position = [11 3 118 22];
app.Button_9.Value = true;
% Create Button_10
app.Button_10 = uiradiobutton(app.ButtonGroup_3);
app.Button_10.Text = '随机生成';
app.Button_10.Position = [198 4 70 22];
% Create Button_11
app.Button_11 = uibutton(app.Panel_3, 'push');
app.Button_11.ButtonPushedFcn = createCallbackFcn(app, @Button_11Pushed, true);
app.Button_11.FontSize = 10;
app.Button_11.Position = [536 199 82 18];
app.Button_11.Text = '确定计算';
% Create Button_12
app.Button_12 = uibutton(app.Panel_3, 'push');
app.Button_12.ButtonPushedFcn = createCallbackFcn(app, @Button_12Pushed, true);
app.Button_12.FontSize = 10;
app.Button_12.Position = [37 7 82 18];
app.Button_12.Text = '确定计算';
% Create Panel_4
app.Panel_4 = uipanel(app.UIFigure);
app.Panel_4.TitlePosition = 'centertop';
app.Panel_4.Title = '恢复';
app.Panel_4.BackgroundColor = [0.9333 0.9137 0.9137];
app.Panel_4.FontWeight = 'bold';
app.Panel_4.FontSize = 16;
app.Panel_4.Position = [1 1 640 176];
% Create TextArea
app.TextArea = uitextarea(app.Panel_4);
app.TextArea.Editable = 'off';
app.TextArea.Position = [325 14 293 86];
% Create Button_8
app.Button_8 = uibutton(app.Panel_4, 'push');
app.Button_8.ButtonPushedFcn = createCallbackFcn(app, @Button_8Pushed, true);
app.Button_8.Position = [517 117 100 25];
app.Button_8.Text = '确定恢复';
% Create Button_7
app.Button_7 = uibutton(app.Panel_4, 'push');
app.Button_7.ButtonPushedFcn = createCallbackFcn(app, @Button_7Pushed, true);
app.Button_7.Position = [206 117 42 25];
app.Button_7.Text = '添加';
% Create EditFieldLabel
app.EditFieldLabel = uilabel(app.Panel_4);
app.EditFieldLabel.HorizontalAlignment = 'right';
app.EditFieldLabel.Position = [103 120 41 22];
app.EditFieldLabel.Text = '秘密值';
% Create iEditField2
app.iEditField2 = uieditfield(app.Panel_4, 'numeric');
app.iEditField2.Position = [148 120 40 22];
% Create iEditFieldLabel
app.iEditFieldLabel = uilabel(app.Panel_4);
app.iEditFieldLabel.HorizontalAlignment = 'right';
app.iEditFieldLabel.Position = [20 120 32 22];
app.iEditFieldLabel.Text = '第i人';
% Create iEditField
app.iEditField = uieditfield(app.Panel_4, 'numeric');
app.iEditField.Position = [59 120 40 22];
% Create UITable3
app.UITable3 = uitable(app.Panel_4);
app.UITable3.ColumnName = {'第i人'; '第i人秘密值'};
app.UITable3.RowName = {};
app.UITable3.ColumnEditable = true;
app.UITable3.Position = [8 11 288 92];
% Create Button_14
app.Button_14 = uibutton(app.Panel_4, 'push');
app.Button_14.ButtonPushedFcn = createCallbackFcn(app, @Button_14Pushed, true);
app.Button_14.Position = [254 116 42 26];
app.Button_14.Text = '清空';
% Create Button_13
app.Button_13 = uibutton(app.UIFigure, 'push');
app.Button_13.ButtonPushedFcn = createCallbackFcn(app, @Button_13Pushed, true);
app.Button_13.BackgroundColor = [0 0.6 1];
app.Button_13.FontColor = [1 1 1];
app.Button_13.Position = [576 710 42 21];
app.Button_13.Text = '清空';
end
end
methods (Access = public)
% Construct app
function app = SharingSecret
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
加法流程:
乘法流程:
(代码实现可能可以通过matlab的函数实现更简单的实现,自己实现和可视化是一天内现学的所以可能有些缺点,但是大致流程是这样的。代码包和生成的.exe文件上传在了我的资源里以及github(https://github.com/xuekema/shamirSecretSharing))