作者looktheghost (看到鬼)
看板MATLAB
标题[问题] 关於m-file的执行
时间Mon Nov 28 07:20:49 2011
小弟找到下面这个m-file, 里面的 vigenere 也是另一个m-file
function ciphertext = encrypt(plaintext, key)
v = vigenere;
% Squeeze out everything except letters and the space character
exclude = regexp(plaintext, '[^a-zA-Z ]');
plaintext(exclude) = [];
% Make the key and the plaintext lower case, and convert to
% numeric values.
key = lower(key) - double('a') + 1;
key(key < 0) = 27;
plaintext = lower(plaintext) - double('a') + 1;
plaintext(plaintext < 0) = 27;
% Replicate the key so that it is as long as the plaintext.
keyIndex = mod(0:(numel(plaintext)-1), numel(key))+1;
k = key(keyIndex);
% Encrypt: C(n) = V(k(n), plaintext(n))
ciphertext = arrayfun(@(m,n) v(m,n), k, plaintext) - 1;
ciphertext(ciphertext == 26) = double(' ') - double('a');
ciphertext = upper(char(ciphertext + double('a')));
但当我输入 plaintext = ['gdhse123'] 以及 key = [2 3 4 5 6 7] 时
他却出现 " plaintext is undefined " 然後错误是发生在
exclude = regexp(plaintext, '[^a-zA-Z ]') 这一行里面
想请教各位大大
是我的 plaintext 输入的格是错误嘛???
如果是的话 请问一下要如何改变呢???
还是我有其他另外没有注意到的错误呢?
谢谢各位大大
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 134.88.248.240