Jump to content

What algorithm was used to invert block shuffling?


raytheon

Recommended Posts

Hi there. I'm reading through PKHeX codebase and I've stumbled upon  list of bytes that can be used to invert shuffling when encrypting the pokemon. I've read through block shuffling section on Bulbapedia but cannot figure out how it was calculated - instead of "mapping" that can be seen in the BlockPosition array which maps easily to A, B, C and D values in the table, this I cannot figure out, but I'd love to hear more about this!

Link to comment
Share on other sites

If you reference the shuffle state table on Bulbapedia, you'll notice that the operation to shuffle back to the resting state is just another shuffle operation with different positions. The inverse is just the index of this result of the regular shuffle table.

A(X) = y

B(y) = x

Both A and B are the same function, just moving 4 chunks to a spot. Find the index of the reverse shuffle result in the regular shuffle list, then just have the algorithm shuffle regularly. Saves you from code duplication and a separate reverse shuffle block position array.

Link to comment
Share on other sites

Och, okay, I get it now!

So if shift value is equal to, lets say 11, then the block order is BDCA. To invert it, I have to look at "inverse" column in the table and look for BDCA string, which is present next to 19 shift value (having in mind that its indexed from zero). Just wanted to explain it here in case anyone will be looking for this answer in the furure.

Thanks a lot!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...