I wanted to try and figure out how X & Y determine Friend Safaris based off of friend codes. I've tried looking for this in a variety of places online (and even in a couple of different languages). A couple of people have suggested that they figured it out, but there's no proof anywhere that I could find. Most threads around this died a few years ago, but I figure some people might still be interested so I thought I'd ask about it here.
Here's what I have found out:
Friend codes seem to be saved within the save file as a truncated 32-bit integer. In other words, the friend code is treated as a 12-digit base-10 integer & then stored in a 32-bit value. This is alongside some other data (like whether or not the 3rd slot is unlocked, or if you've unlocked hidden abilities).
I did find the area in memory that lists the Pokemon in the Friend Safari in order. It's simply a list of 216 Pokemon (any Pokemon with a 50% chance of appearing for a given slot appears twice in the list). I uploaded the list as a text file, for anyone who's interested. It's split into sections, with each line representing one slot & the Pokemon are in the same order as in the game's memory. With the ROM I was looking at, the list starts at address 0x65EDEA, if you want to look for yourself.
I've tried a few different things using friend codes:
1) Using the friend codes directly (like XORing the high and low words, or XORing all of the bytes & then looking at the result mod 18)
2) Using the friend codes as a seed for the PRNG, and then doing more math on that result (more XORs & mod 18 math)
I haven't had any luck discerning any kind of pattern just using math & logical operators. Also, some people have suggested that the Friend Safari is based on additional factors (like region and/or birth date), although I'm not certain about that ... but if it's true, then it would be even more difficult to work it out this way.
The other approach, of course, is to look at the code's disassembly & try to figure it out from that side. Unfortunately, I'm not very good with disassembly, so my attempts there haven't met with any success.