我正在尝试在C#中转换此功能请帮助我

时间:2018-10-19 04:35:15

标签: c# asp.net

Public Function Encrypt(ByRef PassStr As String) As String
        Dim Pos, StrLen, i, iValue As Short
        Dim RetValue As String
        iValue = 100
        StrLen = Len(PassStr)
        RetValue = ""

        For i = 1 To StrLen
            Pos = Asc(Mid(PassStr, i, 1)) + (iValue + i)
            RetValue = RetValue & Chr(Pos)
        Next
        Encrypt = RetValue
    End Function

在我的C#代码中,这是我在for循环中出错的地方..在C#中

public static string Encryptpwd(string password)
{
        try
        {

            // byte[] encData_byte = new byte[password.Length];
            // encData_byte = System.Text.Encoding.UTF8.GetBytes(password);
            // string encodedData = Convert.ToBase64String(encData_byte);
            // return encodedData;
            //for (init; condition; increment)
            //{
            //    statement(s);
            //}
            /// <param name="s"> String to Check.</param> 
            /// <param name="a">Position of Character</param> 
            /// <param name="b">Length </param>  

            int Pos = 0, i = 0, iValue = 0;
            string RetValue = string.Empty;
            iValue = 100;
            RetValue = "";

            int StrLen = password.Length;

            for (i = 1; Mid(password,i,10); iValue +i; )
            {
                Console.WriteLine("value of a: {0}", Pos);
            }

            return password;
        }
        catch (Exception ex)
        {
            throw new Exception("Error in Encryptpwd" + ex.Message);
        }
    }

    public static string Mid(string s, int a, int b)
    {
        string temp = s.Substring(a - 1, b);
        return temp;
    }

2 个答案:

答案 0 :(得分:0)

您可以从converter.telerik.com使用以下内容

public string Encrypt(ref string passStr)
    {
        int pos, strLen, i, iValue;
        string returnValue;
        iValue = 100;
        strLen = passStr.Length;
        returnValue = "";

        for (i = 1; i <= strLen; i++)
        {
            pos = ((int)(Convert.ToChar(passStr.Substring(i, 1))) + (iValue + i));
            returnValue = returnValue + passStr[pos];
        }


        return returnValue;
    }

答案 1 :(得分:0)

您好,您可以使用Online Vb到c#转换器。

喜欢此链接: http://converter.telerik.com/

public string Encrypt(ref string PassStr)
{
    short Pos, StrLen, i, iValue;
    string RetValue;
    iValue = 100;
    StrLen = Strings.Len(PassStr);
    RetValue = "";

    for (i = 1; i <= StrLen; i++)
    {
        Pos = Strings.Asc(Strings.Mid(PassStr, i, 1)) + (iValue + i);
        RetValue = RetValue + Strings.Chr(Pos);
    }
    Encrypt = RetValue;
}