Seppe Dekeyser (rip ) Profile picture
Front-end Developer @ CloudClass and @howestDAE Game Dev Veteran • He/Him • I write weird colored text on a dark background

Jan 22, 2022, 23 tweets

Reverse-engineering wordle to cheat because I'm bad at it.

Obvious spoiler alert:
🧵

#Wordle

So step 1 is to open the dev tools. In the sources tab, you can see that there's two files: our website index.html file, and a main.e65ce0a5.js file. The latter contains all the code that makes the game run.

If we view the file, we see a minimized view of the file. This is likely because the developer used a framework or tool which outputs these minified files.
Let's copy-paste this into vs code and see what we get.

After pretty-printing the contents of this file, we end up with a whopping 15k lines of code. This is very clearly built upon some sort of framework. Possibly react or vue, not too sure.

While scrolling through the code, I saw this pop up in the code outline. Hmmm very interesting, let's investigate.

Sure enough, it's a huge list of words! All of them are 5-letter words, these seem to be the words that the game uses.

Damn, that's a pretty long list. ~2300 words, that should last for at least

*whips out calculator*

6 years.

Anyways, let's figure out how exactly it chooses what word is gonna be the word of the day for today.

The big array containing all the words is called "La". Let's rename it to something more sensible.

There we go.

So now we have to figure out where it reads from this array. A little later on, we find a function called "Da". It looks to take in a parameter called "e", which it uses to call a function, and initialize "a" and "s". these are then used to read from our words array. For my...

sanity, and that of yours, let's rename some of these parameters:

What this function seems to be doing, is it gets the variables "a" and "s", and then picks the word according to that index.
The return statement is a bit weird tho. In JavaScript, there's this thing called the comma operator. Essentially, it executes the left part first, ...

then the right part, and then proceeds to return the right part of the operator.

What's going on here is that the part in between brackets sets "a" to never be larger than the total amount of words in the array. Y'know, for if the game is still around in 6 years...

Alright, time to dig in to what this "GetS" function does...

It seems to be a small function, which returns the result of the function "Na", with a variable called "Ha" and the function's input parameter "e".

Taking a look at "Ha" tells us that it's a specific date, 19th of May, 2021. I'm gonna go out on a limb here, and say that this is the first day of the game.

So what is this "Na" function?
By taking a quick look at it, we can see that it takes the difference between the first date, and the second date.
It also sets the time to 0, and does a rounding calculation.

Let's rename some stuff for our sanity.

So now we know that the "GetS" function returns the amount of days between the start date, and some parameter it gets.
Since our "GetS" function is called in the "GetWordOfTheDay" function, let's see where this gets called, and what it's "someParameter" parameter is doing.

The piece of code where "GetWordOfTheDay" gets called, is pretty messy, but this one line of code explains it all:

We set the "e" variable's "solution" variable to whatever the word of the day is, with what seems to be the current date as input parameter.

The "e" variable seems to be some sort of structure which holds all game data. it has other variables such as "boardState", "hardMode" and "solution".

To bring it back to our "GetWordOfTheDay" function, we now know that "s" is actually the number of the current day in the game. This is also what shows up in the little text that you can copy-paste send to your friends!

So we can now see that we simply:

1. calculate what day number we're on
2. get the word in the words list at that index.

Large thread for such a simple thing... 😅

Thanks for coming to my TED talk.

this is essentially the code that gets the current date number. Simply take this number and grab whatever word is at that that position in the list:

(remember though, arrays start at 0)

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling