vigenere cipher in matlab using function
the code block:
function plaintext = decrypt(ciphertext, key) key = lower(key) - double('a') + 1; key(key < 0) = 27; ciphertext = lower(ciphertext) - double('a') + 1; ciphertext(ciphertext < 0) = 27; keyindex = mod(0:(numel(ciphertext)-1), numel(key))+1; k = key(keyindex); plaintext = arrayfun(@(m,n) find(v(m,:) == n), k, ciphertext) - 1; plaintext(plaintext == 26) = double(' ') - double('a'); plaintext = upper(char(plaintext + double('a'))) end i want decrypt('lxfopvefrnhr', 'lemon') display attackatdawn instead displays atuackaudaxn. can fix this?