
Untitled
By: a guest on
May 16th, 2012 | syntax:
None | size: 0.78 KB | hits: 15 | expires: Never
function out = atbash(in)
vals = double(in); % Cast the string input into a vector of doubles
upperind = find(in >= 65 & in <= 90); % Find all upper case letters
lowerind = find(in >=97 & in <= 122); % Find all lower case letters
in(upperind) = 155 - in(upperind); % Apply the appropriate numerical changes to
% indices of the original string that are
% uppercase.
in(lowerind) = 219 - in(lowerind); % Apply the appropriate numerical changes to
% indices of the original string that are
% lowercase.
% Cast the resulting vector back into a string
other= find(in>0 & in< 65 | in>90 & in<97 | in>122)
in(other) = vals(other)
out = num2str(char(in([1:1:length(in)])))
end