示例#1
0
 public static void EncryptDecrypt(byte[][] adpcm, CriAdxKey key, int encryptionType, int frameSize)
 {
     for (int i = 0; i < adpcm.Length; i++)
     {
         EncryptDecryptChannel(adpcm[i], key, encryptionType, frameSize, i, adpcm.Length);
     }
 }
示例#2
0
        public static void EncryptDecryptChannel(byte[] adpcm, CriAdxKey key, int encryptionType, int frameSize, int channelNum, int channelCount)
        {
            int xor        = key.Seed;
            int frameCount = adpcm.Length.DivideByRoundUp(frameSize);

            for (int i = 0; i < channelNum; i++)
            {
                xor = (xor * key.Mult + key.Inc) & 0x7fff;
            }

            for (int i = 0; i < frameCount; i++)
            {
                int pos = i * frameSize;
                if (FrameNotEmpty(adpcm, pos, frameSize))
                {
                    adpcm[pos] ^= (byte)(xor >> 8);
                    if (encryptionType == 9)
                    {
                        adpcm[pos] &= 0x1f;
                    }
                    adpcm[pos + 1] ^= (byte)xor;
                }

                for (int c = 0; c < channelCount; c++)
                {
                    xor = (xor * key.Mult + key.Inc) & 0x7fff;
                }
            }
        }
示例#3
0
        private static bool TestKey(CriAdxKey key, int encryptionType, ushort[] scales)
        {
            int validationMask = encryptionType == 8 ? 0xE000 : 0x1000;
            int xorMask        = 0x7fff;

            int xor = key.Seed;

            foreach (ushort scale in scales)
            {
                if (((scale ^ xor) & validationMask) != 0 && scale != 0)
                {
                    return(false);
                }
                xor = (xor * key.Mult + key.Inc) & xorMask;
            }
            return(true);
        }