python 代码转c#,求大神帮忙

def generate_ep(vid, ep):
f_code_1 = 'becaf9be'
f_code_2 = 'bf7e5f01'
def trans_e(a, c):
f = h = 0
b = list(range(256))
result = ''
while h < 256:
f = (f + b[h] + ord(a[h % len(a)])) % 256
b[h], b[f] = b[f], b[h]
h += 1
q = f = h = 0
while q < len(c):
h = (h + 1) % 256
f = (f + b[h]) % 256
b[h], b[f] = b[f], b[h]
if isinstance(c[q], int):
result += chr(c[q] ^ b[(b[h] + b[f]) % 256])
else:
result += chr(ord(c[q]) ^ b[(b[h] + b[f]) % 256])
q += 1
return result
e_code = trans_e(f_code_1, base64.b64decode(ep))
sid, token = e_code.split('_')
new_ep = trans_e(f_code_2, '%s_%s_%s' % (sid, vid, token))
return base64.b64encode(bytes(new_ep, 'latin')), sid, token
#return base64.b64encode(new_ep)

string trans_e(string a,string c) {
    int f = 0,h = 0,last = 0;
    int b[256];
    string result = "";
    while (h < 256) {
        f = (f + b[h] + Convert.ToInt32(a[h % a.Length])) % 256
        last = b[h];
        b[h] = b[f];
        b[f] = last;
        h += 1;
    }
    int q = 0,f = 0,h = 0;
    while (q < c.Length ) {
        h = (h + 1) % 256;
        f = (f + b[h]) % 256;
        last = b[h];
        b[h] = b[f];
        b[f] = last;
        int outint = 0;
        if ( int.TryParse(c[q].ToString(),out outint) ) {
            result += Convert.ToChar(c[q] ^ b[(b[h] + b[f]) % 256]);
        } else {
            result += Convert.ToChar(Conver.ToInt32(c[q]) ^ b[(b[h] + b[f]) % 256]);
            q += 1;
        }
        return result;
}
string[] generate_ep(string vid, string ep) {
    string result[3];
    string f_code_1 = "becaf9be";
    string f_code_2 = "bf7e5f01";
    string e_code = trans_e(f_code_1, Convert.FromBase64String(ep));
    string sid = e_code.Split("_")[0];
    string token = e_code.Split("_")[1];
    string new_ep = trans_e(f_code_2, sid + "_" + vid + "_" + token))
    result[0] = Convert.ToBase64String(Encoding.GetEncoding("lanin").GetString(new_ep));
    result[1] = sid;
    result[2] = token;
    return result;
}追问

string e_code = trans_e(f_code_1, Convert.FromBase64String(ep));
这行中的第二个参数是数组
string new_ep = trans_e(f_code_2, sid + "_" + vid + "_" + token))
这行中的第二个参数是字符串
这里应该是有问题的,大神能不能再改改

追答

第一句改成这样:
string dbase64 = new string(Convert.FromBase64String(ep));
string e_code = trans_e(f_code_1, dbase64);
第二句:
第二个参数就是字符串了啊

温馨提示:答案为网友推荐,仅供参考
相似回答