Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. function plaintext = decrypt(ciphertext, key)
  2.  
  3. key = lower(key) - double('a') + 1;
  4. key(key < 0) = 27;
  5. ciphertext = lower(ciphertext) - double('a') + 1;
  6. ciphertext(ciphertext < 0) = 27;
  7.  
  8. keyIndex = mod(0:(numel(ciphertext)-1), numel(key))+1;
  9. k = key(keyIndex);
  10.  
  11. plaintext = arrayfun(@(m,n) find(v(m,:) == n), k, ciphertext) - 1;
  12. plaintext(plaintext == 26) = double(' ') - double('a');
  13. plaintext = upper(char(plaintext + double('a')))
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement