C#'s IncrementArray and Array.Copy functions

本文关键字:and Array Copy functions IncrementArray | 更新日期: 2023-09-27 17:58:56

我正试图将一个用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函数是如何工作的,我将不胜感激。

C#'s IncrementArray and Array.Copy functions

Array.Copy将数据从一个阵列复制到另一个阵列:

  • incPKGFileKey是源数组
  • 0是源数组中开始复制的偏移量
  • PKGFileKeyConsec是目标阵列
  • pos是目标数组中开始复制到的偏移量
  • PKGFileKey.Length是要复制的数组项数

据我所知,IncrementArray不是.NET框架的一部分,应该在项目中的某个地方定义。

Array.Copy与任何其他.NET类型或方法一样,在MSDN库中进行了描述:http://msdn.microsoft.com/en-us/library/y5s0whfd.aspx

IncrementArray显然在您的代码中(在同一个类或这个类的基类中),所以您必须阅读该代码。