From 60aa130f091a1b8a02889fb6a485835f673f8350 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 21 Mar 2018 09:50:49 +0400 Subject: [PATCH] (KiriKiri): another encryption scheme. --- ArcFormats/KiriKiri/CryptAlgorithms.cs | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ArcFormats/KiriKiri/CryptAlgorithms.cs b/ArcFormats/KiriKiri/CryptAlgorithms.cs index 99dc4230..da9b0e05 100644 --- a/ArcFormats/KiriKiri/CryptAlgorithms.cs +++ b/ArcFormats/KiriKiri/CryptAlgorithms.cs @@ -1278,5 +1278,38 @@ namespace GameRes.Formats.KiriKiri buffer[pos+i] ^= key[key_pos++ % 0x1F]; } } + + public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + Decrypt (entry, offset, buffer, pos, count); + } + } + + [Serializable] + public class SmxCrypt : ICrypt + { + public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + var key = new byte[6] { + (byte)(entry.Hash >> 5), + (byte)(entry.Hash >> 4), + (byte)(entry.Hash >> 3), + (byte)(entry.Hash >> 2), + (byte)(entry.Hash >> 2), + (byte)(entry.Hash >> 3), + }; + for (int i = 0; i < count; ++i) + { + if ((offset + i) <= 100) + buffer[pos+i] ^= key[3]; + else + buffer[pos+i] ^= key[(int)(offset + i) & 5]; + } + } + + public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + Decrypt (entry, offset, buffer, pos, count); + } } }