crt.m

来自「vigenere密码解密的matlab实现」· M 代码 · 共 24 行

M
24
字号
function x = crt(a,m);% This function solves the Chinese Remainder Theorem problem:%   x= a(1) mod m(1)%   x= a(2) mod m(2)%   ...%   x= a(r) mod m(r)% The values for a and m should be a vector of the same dimensionif any(size(a) ~= size(m)),   error('The vectors a and m should be the same size');end;r=length(a);M=prod(m);  % calculate the total modulusx=0;for j=1:r,   x=x+ a(j)*(M/m(j))*invmodn(M/m(j),m(j));   x=mod(x,M);end;      

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?