From cb2b6e2f43e301cb8fabd9facbf4df26b32eff86 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 12 Sep 2017 17:35:11 +0400 Subject: [PATCH] (KiriKiri): another encryption scheme. --- ArcFormats/KiriKiri/CryptAlgorithms.cs | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ArcFormats/KiriKiri/CryptAlgorithms.cs b/ArcFormats/KiriKiri/CryptAlgorithms.cs index 12d8d03d..8de0bda6 100644 --- a/ArcFormats/KiriKiri/CryptAlgorithms.cs +++ b/ArcFormats/KiriKiri/CryptAlgorithms.cs @@ -744,7 +744,7 @@ namespace GameRes.Formats.KiriKiri Decrypt (entry, offset, buffer, pos, count); } - IEnumerable GetKey (uint hash) + internal IEnumerable GetKey (uint hash) { hash = (hash ^ m_seed) & 0x7FFFFFFF; hash = hash << 31 | hash; @@ -1142,4 +1142,29 @@ namespace GameRes.Formats.KiriKiri [NonSerialized] Dictionary KnownNames = null; } + + [Serializable] + public class MadoCrypt : AkabeiCrypt + { + public MadoCrypt (uint seed) : base (seed) + { + } + + public override byte Decrypt (Xp3Entry entry, long offset, byte value) + { + int key_pos = (int)offset % 0x1F; + var key = GetKey (entry.Hash).ElementAt (key_pos); + return (byte)(value ^ key); + } + + public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + var key = GetKey (entry.Hash).ToArray(); + int key_pos = (int)offset; + for (int i = 0; i < count; ++i) + { + buffer[pos+i] ^= key[key_pos++ % 0x1F]; + } + } + } }