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

Reply via email to