another KiriKiri encryption scheme.

This commit is contained in:
morkt 2017-06-03 03:45:06 +04:00
parent abd6ff6b39
commit 2d186edb39
4 changed files with 49 additions and 4 deletions

View File

@ -976,4 +976,49 @@ namespace GameRes.Formats.KiriKiri
Decrypt (entry, offset, data, pos, count); Decrypt (entry, offset, data, pos, count);
} }
} }
[Serializable]
public class PuCaCrypt : ICrypt
{
public uint[] HashTable;
public byte[] KeyTable;
public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
{
if (HashTable != null)
{
int i = Array.IndexOf (HashTable, entry.Hash);
if (i != -1)
{
for (int j = 0; j < count; ++j)
buffer[pos+j] ^= KeyTable[i];
return;
}
}
var hash_table = new byte[32];
uint hash = entry.Hash;
for (int k = 0; k < 32; k += 4)
{
if (0 != (hash & 1))
hash |= 0x80000000;
else
hash &= 0x7FFFFFFF;
LittleEndian.Pack (hash, hash_table, k);
hash >>= 1;
}
var key_table = new byte[0x400];
for (int l = 0; l < 32; ++l)
{
for (int m = 0; m < 32; ++m)
key_table[32 * l + m] = (byte)(~hash_table[l] ^ hash_table[m]);
}
for (int n = 0; n < count; ++n)
buffer[pos+n] ^= key_table[(offset + n) & 0x3FF];
}
public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
{
Decrypt (entry, offset, buffer, pos, count);
}
}
} }

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("1.2.33.1382")] [assembly: AssemblyVersion ("1.2.33.1383")]
[assembly: AssemblyFileVersion ("1.2.33.1382")] [assembly: AssemblyFileVersion ("1.2.33.1383")]

Binary file not shown.

View File

@ -12,10 +12,10 @@
</Notes> </Notes>
</Release> </Release>
<FormatsData> <FormatsData>
<FileVersion>66</FileVersion> <FileVersion>67</FileVersion>
<Url>https://github.com/morkt/GARbro/raw/master/ArcFormats/Resources/Formats.dat</Url> <Url>https://github.com/morkt/GARbro/raw/master/ArcFormats/Resources/Formats.dat</Url>
<Requires> <Requires>
<Assembly Name="ArcFormats" Version="1.2.31.1367"/> <Assembly Name="ArcFormats" Version="1.2.33.1383"/>
<Assembly Name="GameRes" Version="1.4.26.238"/> <Assembly Name="GameRes" Version="1.4.26.238"/>
</Requires> </Requires>
</FormatsData> </FormatsData>