[your code here]

Jos van Uden user at domain.invalid
Sun Jan 15 06:23:33 PST 2012


import std.conv, std.traits, std.ascii;

S rot13(S)(S s) if (isSomeString!S) {
     return rot(s, 13);
}

S rot(S)(S s, int key) if (isSomeString!S) {
     dchar[] r = new dchar[s.length];

     foreach (i, dchar c; s) {
         if (isLower(c))
             c = ((c - 'a' + key) % 26 + 'a');
         else if (isUpper(c))
             c = ((c - 'A' + key) % 26 + 'A');
         r[i] = c;
     }
     return to!S(r);
}


---

still learning this stuff, feel free to correct or improve

Jos


More information about the Digitalmars-d mailing list