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]; + } + } + } }