将JavaScript加密和解密转换为C#

我找到了用于加密和解密字符串的JavaScript代码。我想在不使用任何算法的情况下转换为C#。 如果有更好的源代码可以在Javascript和C#中使用,谢谢。

   var _charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%";

生成密钥以加密字符串

function generateKey() {
var str = "";
var tar;
tar = new Array();
for (var c = 0; c < _charset.length; c++) {
    tar.push(_charset.substr(c, 1));
}
for (var c = 0; c < _charset.length; c++) {
    str += tar.splice(Math.round(Math.random() * (tar.length - 1)), 1);
}
return str;
}

加密字符串

function encrypt(v, _key) {
var str = "";
var key = _key;
if (_key.length > 0 && v.length > 0) {
    //v = Server.URLEncode(v);
    for (var c = 0; c < v.length; c++) {
        var ch = _charset.indexOf(v.substr(c, 1));
        if (ch > -1) {
            str += key.substr(ch, 1);
            key = rotateKey(key, v.charCodeAt(c));
        }
    }
    return str;
} else {
    return "";
}
}

解密字符串

function decrypt(v, _key) {
var str = "";
var key = _charset;
if (_key.length > 0 && v.length > 0) {
    for (var c = 0; c < v.length; c++) {
        var ch = _key.indexOf(v.substr(c, 1));
        if (ch > -1) {
            str += key.substr(ch, 1);
            key = rotateKey(key, -key.charCodeAt(ch));
        }
    }
    return str;
} else {
    return "";
}
}

function rotateKey(s, amt) {
amt = amt % s.length;
if (amt < 0) {
    amt = s.length + amt;
}
if (amt != 0) {
    return s.substr(s.length - amt, amt) + s.substr(0, s.length - amt);
} else {
    return unescape(s);
}
}