Skip to content

Commit

Permalink
(KiriKiri): another encryption algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
morkt committed Mar 30, 2020
1 parent e061687 commit d90e65c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ArcFormats/KiriKiri/CryptAlgorithms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,4 +1368,42 @@ public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int po
Decrypt (entry, offset, buffer, pos, count);
}
}

[Serializable]
public class NekoWorksCrypt : ICrypt
{
byte[] DefaultKey;

public NekoWorksCrypt (byte[] key)
{
DefaultKey = key;
}

public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
{
var key = InitKey (entry.Hash);
for (int i = 0; i < count; ++i)
{
buffer[pos+i] ^= key[(offset + i) % 31];
}
}

public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count)
{
Decrypt (entry, offset, buffer, pos, count);
}

byte[] InitKey (uint hash)
{
hash &= 0x7FFFFFFF;
hash = hash << 31 | hash;
var key = DefaultKey.Clone() as byte[];
for (int i = 0; i < 31; ++i)
{
key[i] ^= (byte)hash;
hash = (hash & 0xFFFFFFFE) << 23 | hash >> 8;
}
return key;
}
}
}

0 comments on commit d90e65c

Please sign in to comment.