public static void Crypt(HcaInfo hca, byte[][] audio, CriHcaKey key, bool doDecrypt) { for (int frame = 0; frame < hca.FrameCount; frame++) { CryptFrame(hca, audio[frame], key, doDecrypt); } }
public static void DecryptFrame(HcaInfo hca, byte[] audio, CriHcaKey key) { for (int b = 0; b < hca.FrameSize; b++) { audio[b] = key.DecryptionTable[audio[b]]; } }
public static void CryptFrame(HcaInfo hca, byte[] audio, CriHcaKey key, bool doDecrypt) { byte[] substitutionTable = doDecrypt ? key.DecryptionTable : key.EncryptionTable; for (int b = 0; b < hca.FrameSize - 2; b++) { audio[b] = substitutionTable[audio[b]]; } ushort crc = Crc.Compute(audio, hca.FrameSize - 2); audio[hca.FrameSize - 2] = (byte)(crc >> 8); audio[hca.FrameSize - 1] = (byte)crc; }
private static bool TestKey(CriHcaFrame frame, byte[][] audio, CriHcaKey key, byte[] buffer) { int startFrame = FindFirstNonEmptyFrame(audio); int endFrame = Math.Min(audio.Length, startFrame + FramesToTest); for (int i = startFrame; i < endFrame; i++) { Array.Copy(audio[i], buffer, audio[i].Length); CryptFrame(frame.Hca, buffer, key, true); var reader = new BitReader(buffer); if (!CriHcaPacking.UnpackFrame(frame, reader)) { return(false); } } return(true); }