Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 0.78 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. function out = atbash(in)
  3. vals = double(in); % Cast the string input into a vector of doubles
  4. upperind = find(in >= 65 & in <= 90); % Find all upper case letters
  5. lowerind = find(in >=97 & in <= 122); % Find all lower case letters
  6. in(upperind) = 155 - in(upperind); % Apply the appropriate numerical changes to
  7.                            % indices of the original string that are
  8.                            % uppercase.
  9. in(lowerind) = 219 - in(lowerind); % Apply the appropriate numerical changes to
  10.                            % indices of the original string that are
  11.                            % lowercase.
  12.  % Cast the resulting vector back into a string
  13. other= find(in>0 & in< 65 | in>90 & in<97 | in>122)
  14. in(other) = vals(other)
  15. out = num2str(char(in([1:1:length(in)])))
  16. end