PKHeX.Form1.openXOR C# (CSharp) Method

openXOR() private method

private openXOR ( byte input, string path ) : bool
input byte
path string
return bool
        private bool openXOR(byte[] input, string path)
        {
            // Detection of stored Decryption XORpads:
            if (ModifierKeys == Keys.Control) return false; // no xorpad compatible
            byte[] savID = new byte[0x10]; Array.Copy(input, 0x10, savID, 0, 0x10);
            string exepath = Application.StartupPath;
            string xorpath = exepath.Clone().ToString();
            string[] XORpads = Directory.GetFiles(xorpath);

            check:
            foreach (byte[] data in from file in XORpads let fi = new FileInfo(file) where (fi.Name.ToLower().Contains("xorpad") || fi.Name.ToLower().Contains("key")) && (fi.Length == 0x10009C || fi.Length == 0x100000) select File.ReadAllBytes(file))
            {
                // Fix xorpad alignment
                byte[] xorpad = data;
                if (xorpad.Length == 0x10009C)
                {
                    Array.Copy(xorpad, 0x9C, xorpad, 0, 0x100000);
                    Array.Resize(ref xorpad, 0x100000);
                }
                byte[] xorID = new byte[0x10]; Array.Copy(xorpad, 0x10, xorID, 0, 0x10);
                if (!xorID.SequenceEqual(savID)) continue;

                // Set up Decrypted File
                byte[] decryptedPS = new byte[0x76000];
                Array.Copy(input, 0x5400, decryptedPS, 0, 0x76000);

                // xor through and decrypt
                for (int z = 0; z < 0x76000; z++)
                    decryptedPS[z] ^= xorpad[0x5400 + z];

                // Weakly check the validity of the decrypted content
                if (BitConverter.ToUInt32(decryptedPS, 0x76000 - 0x1F0) != 0x42454546) // Not OR/AS
                    if (BitConverter.ToUInt32(decryptedPS, 0x65600 - 0x1F0) != 0x42454546)
                        continue; // Not X/Y, so continue.
                    else
                        Array.Resize(ref decryptedPS, 0x65600); // set to X/Y size
                else Array.Resize(ref decryptedPS, 0x76000); // set to ORAS size just in case

                // Save file is now decrypted! Reset the loading variables.
                bool oras = (decryptedPS.Length == 0x76000);
                string GameType = oras ? "ORAS" : "XY";

                // Trigger Loading of the decrypted save file.
                openMAIN(decryptedPS, path, GameType, oras);

                // Abort the opening of a non-cyber file.
                return true;
            }
            // End file check loop, check the input path for xorpads too if it isn't the same as the EXE (quite common).
            if (xorpath != exepath) return false; // no xorpad compatible
            xorpath = Path.GetDirectoryName(path); goto check;
        }
        private void openSave(bool oras)
Form1