Something like the following?
public static string Rot13(string text) {
char[] chars = text.ToCharArray();
for (int i = 0; i < chars.Length; i++) {
int number = (int)chars;
if (number >= 'a' && number <= 'z') {
if (number > 'm')
number -= 13;
else
number += 13;
} else if (number >= 'A' && number <= 'Z') {
if (number > 'M') {
number -= 13;
} else {
number += 13;
}
}
chars = (char)number;
}
return new string(chars);
}
I am not sure if the á, ç, À, Õ, etc characters are considered this
way.
I would like to use this for email obfuscation so I need to have the
obfuscation on the client and on the server done in the same way. On
the client I have:
$.rotate13 = function(s) {
var b = [],c,i = s.length,a = 'a'.charCodeAt(),z = a + 26,A=
'A'.charCodeAt(),Z = A + 26;
while (i--) {
c = s.charCodeAt(i);
if (c >= a && c < z) { b = String.fromCharCode(((c - a
+ 13) % (26)) + a); }
else if (c >= A && c < Z) { b = String.fromCharCode(((c
- A + 13) % (26)) + A); }
else { b = s.charAt(i); }
}
return b.join('');
};
This is a JQuery function.
Thanks,
Miguel