From c5aee52d96af213ffc55f23f877e349d8dd9c868 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 11 Aug 2015 07:06:00 +0400 Subject: [PATCH] (DameganeCrypt): another decryption scheme. --- ArcFormats/ArcXP3.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ArcFormats/ArcXP3.cs b/ArcFormats/ArcXP3.cs index 97d18eea..fb471725 100644 --- a/ArcFormats/ArcXP3.cs +++ b/ArcFormats/ArcXP3.cs @@ -92,6 +92,7 @@ namespace GameRes.Formats.KiriKiri { arcStrings.ArcNoEncryption, NoCryptAlgorithm }, { "Cafe Sourire", new XorCrypt (0xcd) }, { "Coμ", new ComyuCrypt() }, + { "Damegane", new DameganeCrypt() }, { "Fate/hollow ataraxia", new FateHACrypt() }, { "Fate/stay night", new FateCrypt() }, { "Imouto Style", new ImoutoStyleCrypt() }, @@ -1055,4 +1056,31 @@ NextEntry: } } } + + internal class DameganeCrypt : ICrypt + { + public override byte Decrypt (Xp3Entry entry, long offset, byte value) + { + if (0 != (offset & 1)) + return (byte)(value ^ entry.Hash); + else + return (byte)(value ^ offset); + } + + public override void Decrypt (Xp3Entry entry, long offset, byte[] values, int pos, int count) + { + for (int i = 0; i < count; ++i, ++offset) + { + if (0 != (offset & 1)) + values[pos+i] ^= (byte)entry.Hash; + else + values[pos+i] ^= (byte)offset; + } + } + + public override void Encrypt (Xp3Entry entry, long offset, byte[] values, int pos, int count) + { + Decrypt (entry, offset, values, pos, count); + } + } }