0

我正在尝试将用 C# 制作的应用程序移植到 Ruby,但我无法理解几个函数。

这是代码。

for (int pos = 0; pos < EncryptedData.Length; pos += AesKey.Length)
{
    Array.Copy(incPKGFileKey, 0, PKGFileKeyConsec, pos, PKGFileKey.Length);

    IncrementArray(ref incPKGFileKey, PKGFileKey.Length - 1);
}

private Boolean IncrementArray(ref byte[] sourceArray, int position)
{
    if (sourceArray[position] == 0xFF)
    {
        if (position != 0)
        {
            if (IncrementArray(ref sourceArray, position - 1))
            {
                sourceArray[position] = 0x00;
                return true;
            }
            else return false;
        }
        else return false;
    }
    else
    {
        sourceArray[position] += 0x01;
        return true;
    }
}

我知道数组和键的长度是 16。如果有人能解释 Array.Copy 和 IncrementArray 函数的工作原理,我将不胜感激。

4

2 回答 2

0

Array.Copy copies data from one array to the other:

  • incPKGFileKey is the source array
  • 0 is the offset in the source array to start copying from
  • PKGFileKeyConsec is the destionation array
  • pos is the offset to in the destination array start copying to
  • PKGFileKey.Length is the number of array items to copy

IncrementArray, to my knowledge, is not part of the .NET framework, and should be defined somewhere in your project.

于 2013-02-13T22:31:35.007 回答
0

Array.Copy is described, like any other .NET type or method, in MSDN library: http://msdn.microsoft.com/en-us/library/y5s0whfd.aspx

IncrementArray is obviously in your code (in the same class or the base class of this one), so you will have to read that code.

于 2013-02-13T22:32:27.000 回答