Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c语言中NX客户端的密码置乱算法#_C#_C++_Windows_Nomachine Nx - Fatal编程技术网

C# c语言中NX客户端的密码置乱算法#

C# c语言中NX客户端的密码置乱算法#,c#,c++,windows,nomachine-nx,C#,C++,Windows,Nomachine Nx,我目前正在尝试从QT-C移植NX的密码置乱算法++ 到C# 资料来源: 我当前的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace mynamespace { class NxScramble { string ToScramble = ""; int numValidCharList = 85; String dummy

我目前正在尝试从QT-C移植NX的密码置乱算法++ 到C#

资料来源:

我当前的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mynamespace
{
class NxScramble
{
    string ToScramble = "";
    int numValidCharList = 85;
    String dummyString = "{{{{";

    char[] validCharList = new char[]
    {
      '!',  '#',  '$',  '%',  '&',  '(', ')',  '*',  '+',  '-',
      '.',  '0',   '1',  '2',   '3',  '4',  '5',  '6', '7', '8',
      '9', ':',  ';',  '<',  '>',  '?',  '@',  'A',  'B', 'C',
      'D',  'E',  'F',  'G',  'H',  'I',  'J',  'K',  'L', 'M',
      'N', 'O',  'P',  'Q',  'R',  'S',  'T', 'U', 'V', 'W',
      'X',  'Y',  'Z',  '[', ']',  '_',  'a',  'b',  'c',  'd',
      'e',  'f',  'g',  'h',  'i',  'j',  'k',  'l',  'm',  'n',
      'o',  'p',  'q',  'r',  's',  't',  'u',  'v',  'w',  'x',
      'y',  'z',  '{',  '|',  '}'
    };

    public NxScramble(string s)
    {
        ToScramble = s;
    }

    public string scrambleString()
    {
        string sRet = "";

        if (ToScramble == null || ToScramble.Equals(""))
        {
            return ToScramble;
        }

        string str = encodePassword(ToScramble);

        if (str.Length < 32)
        {
            str += dummyString;
        }

        for (int iR = (str.Length - 1); iR >= 0; iR--)
        {
            //
            // Reverse string
            //
            sRet += str.ElementAt(iR);
        }

        if (sRet.Length < 32)
        {
            sRet += dummyString;
        }

        int k = getRandomValidCharFromList();
        int l = k + sRet.Length - 2;

        sRet.Insert(0, k.ToString());

        string retStr = "";

        for (int i1 = 1; i1 < sRet.Length; i1++)
        {
            int j = findCharInList(sRet.ElementAt(i1));

            if (j == -1)
            {
                return ToScramble;
            }
            int i = (j + l * (i1 + 1)) % validCharList.Length;
            /*
             * sRet.ref(i1) = validCharList[i];
             */
            retStr += validCharList[i];
        }

        char c = (char)(getRandomValidCharFromList() + 2);
        sRet += c;

        retStr = retStr.Replace("&", @"&amp;");
        retStr = retStr.Replace("\"", @"&quot;");
        retStr = retStr.Replace("'", @"&apos;");
        retStr = retStr.Replace("<", @"&lt;");
        retStr = retStr.Replace(">", @"&gt;");

        return retStr;
    }

    private string encodePassword(string p)
    {
        string sPass = ":";
        string sTmp = "";

        if (p.Equals(""))
        {
            return "";
        }

        for (int i = 0; i < p.Length; i++)
        {
            char c = (char)p.ElementAt(i);
            sTmp = String.Format("{0:d}:", (c + i + 1));
            sPass += sTmp;
            sTmp = "";
        }

        return sPass;
    }

    private int findCharInList(char c)
    {
        int i = -1;

        for (int j = 0; j < numValidCharList; j++)
        {
            if (validCharList[j] == c)
            {
                i = j;
                return i;
            }
        }
        return i;
    }

    private char getRandomValidCharFromList()
    {
        int k = DateTime.Now.Second;
        return validCharList[k];
    }

}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
名称空间mynamespace
{
NX类加扰
{
字符串ToScramble=“”;
int numValidCharList=85;
字符串dummyString=“{{{{}”;
char[]validCharList=新字符[]
{
'!',  '#',  '$',  '%',  '&',  '(', ')',  '*',  '+',  '-',
'.',  '0',   '1',  '2',   '3',  '4',  '5',  '6', '7', '8',
"9",":",",",","A,"B","C",,
‘D’、‘E’、‘F’、‘G’、‘H’、‘I’、‘J’、‘K’、‘L’、‘M’,
“N”、“O”、“P”、“Q”、“R”、“S”、“T”、“U”、“V”、“W”,
‘X’、‘Y’、‘Z’、‘[’、’]、‘a’、‘b’、‘c’、‘d’,
‘e’、‘f’、‘g’、‘h’、‘i’、‘j’、‘k’、‘l’、‘m’、‘n’,
‘o’、‘p’、‘q’、‘r’、‘s’、‘t’、‘u’、‘v’、‘w’、‘x’,
“y”,“z”,“{”,“|”,“}”
};
公用NxScramble(字符串s)
{
ToScramble=s;
}
公共字符串加扰字符串()
{
字符串sRet=“”;
if(ToScramble==null | | ToScramble.Equals(“”)
{
返回到可恢复状态;
}
字符串str=encodePassword(ToScramble);
如果(str.Length<32)
{
str+=dummyString;
}
对于(int-iR=(str.Length-1);iR>=0;iR--)
{
//
//反向串
//
sRet+=str.ElementAt(iR);
}
如果(sRet.Length<32)
{
sRet+=dummyString;
}
int k=getRandomValidCharFromList();
int l=k+sRet.Length-2;
sRet.Insert(0,k.ToString());
字符串retStr=“”;
for(int i1=1;i1
它根据给定的密码生成一个字符串,我将其添加到 nxclient的XML配置文件:

        NxScramble nxs = new NxScramble(passPhrase);
        string ScambledPass = nxs.scrambleString();

        string nxconfig = @"
        ....
        ....
        <group name='Login' >
        <option key='Auth' value='"+ ScambledPass + @"' />
        <option key='Guest Mode' value='false' />
        <option key='Guest password' value='' />
        <option key='Guest username' value='' />
        <option key='Login Method' value='nx' />
        <option key='Public Key' value='
        .........
        .........
        ' />
        <option key='User' value='" + username + @"' />
        </group>
        ";
NxScramble-nxs=新的NxScramble(密码短语);
string ScambledPass=nxs.scrambleString();
字符串nxconfig=@”
....
....
";
但是NXClient一直说“身份验证失败”,所以我很确定 在C++代码的C语言端口中肯定有错误。 特别是我不确定这行原始代码: sRet.ref(i1)=有效字符列表[i]

我不知道ref(i1)在做什么

如果有人发现我的错误就好了:)


提前感谢

scrambleString()的上部代码部分
会初始化并处理
sRet
, 以及
retStr
上的下半部分,最后返回该部分进行工作
sRet
根本不用。您可能应该将
retStr
/
sRet
组合起来,也许只是 使用一个字符串

sRet.ref(i1) = validCharList[i]
上面的代码只是一个简单的字符分配,取代了pos上的字符
i1
sRet
中,在pos
i
处使用字符串
validCharList
中的字符