It’s 1st January 2022 β while enjoying vacations from work, I kept hearing about this word puzzle called Wordle β and figured I’d learn how it works. It’s gone from dozens of players to hundreds of thousands in a few months, created by Josh Wardle β a software engineer in Brooklyn for his partner. This post has no spoilers.
Wordle Solved: Reverse Engineering and Hacking Wordle
Ahmad AwaisReverse Engineering Wordle#
While I did enjoy playing it for a day or two β soon after, I started to wonder if I could create a CLI to solve this game for me. You know I love creating CLIs, right?
If you’re new here, then you need to know that I’m a big fan of automation. I have created hundreds of free and open-source CLIs, even a CLI to create CLIs, and a 10-hour long course with 22 projects and 100 videos β where I teach how to bend JavaScript to your will, separating yourself from 99% of humankind, and building any kind of automation software. It’s called NodeCLI.com.
Looking under the hood#
As any web developer could imagine β I started by inspecting the source code. I figured there must be some API endpoint with a database of words. Messing around with the Network tab, I found nothing.
The AHA moment#
For a while, I was like, meh Β―\_(γ)_/Β― looks like we’re going down the rabbit hole, ain’t we. But you know, before I do that, let’s check if there’s something stored in the localStorage. I found the entire game state with the solution
key inside there, to my surprise. π₯³
The OMG.WTF?BBQ! moment#
No network requests. Game’s solution in localStorage.
Something tells me there’s more to the story here. Let’s search for the word REBUS
(the wordle solution today 2022-01-01). Nops didn’t find anything.
Let’s look for the JavaScript files. And there it was, a huge array of words defined as a variable La
that Wordle uses in combination with dates to give us so much more pain (fun?!) during the pandemic.
var La = ["cigar", "rebut", "β¦ 2,315 more words"]
Figuring out the algorithm#
At this point, I knew I had discovered today’s solution and the entire list of words. All I needed to do was reverse engineer the minified JavaScript file to figure out how one of the words gets picked.
Skimming through over 15,625 lines of code, I found a function called Da
.
function Da(e) {
var a, s = Ga(e);
return (a = s % La.length), La[a];
}
This function calls another function Ga
to find an index which is then used to find a single word from a gigantic list of words defined as La
.
Funny enough, right after this function is the Ga
function:
function Ga(e) {
return Na(Ha, e);
}
OMG, yet another function call in here called Na
and another variable Ha
. Upon searching, I found the Ha
variable. This looks like a date in 2021. Maybe this is when the Wordle game was launched?! The day zero.
var Ha = new Date(2021, 5, 19, 0, 0, 0, 0);
Oh, such fun, much luck β right below Ha
I found the Na
function:
function Na(e, a) {
var s = new Date(e),
t = new Date(a).setHours(0, 0, 0, 0) - s.setHours(0, 0, 0, 0);
return Math.round(t / 864e5);
}
THIS. IS. IT. Evidently, this function finds the number of days between two dates and then rounds it off to an integer value for finding a word on that index from the La
words list.
And finally, the mysterious input e
in all of these functions was today’s date. This bugger was a bit hard to find.
(e.today = new Date());
And just like that, I was able to reverse engineer the following code, which picks up the words for yesterday, today, and tomorrow even.
function convertDateToIndex(e, a) {
let s = new Date(e),
t = new Date(a).setHours(0, 0, 0, 0) - s.setHours(0, 0, 0, 0);
return Math.floor(t / 864e5);
}
let baseDate = new Date(2021, 5, 19, 0, 0, 0, 0);
function getIndex(todaysDate) {
return convertDateToIndex(baseDate, todaysDate);
}
function getSolution(today) {
let a,
s = getIndex(today);
return (a = s % wordleWords.length), wordleWords[a];
}
let today = new Date();
let yesterday = new Date().setDate(today.getDate() - 1);
let tomorrow = new Date().setDate(today.getDate() + 1);
Wordle Solved JavaScript Bookmarklet#
Create and install this bookmarklet to help solve Wordle.
Make a new bookmark in your browser (right-click on the bookmarks bar and click Add Page...
)
- For the
Name
you might put “Wordle Solved”. - Copy the code block below, paste this into the
URL
of a new bookmark.
javascript:alert("Wordle Solved: "+JSON.parse(window.localStorage.getItem("gameState")).solution.toUpperCase())
Navigate to Wordle and click the bookmarklet. Voila!
Wordle-solved Chrome Extension#
Looking for a more fancy solution, with the words listed for yesterday, today, and tomorrow β well, it’s your lucky day. I built a Chrome extension called wordle-solved. I love those animations. Yay!
- π¦ Chrome extension that solves Wordle puzzles for you
- π€― Automatic prediction of the upcoming word tomorrow
You can read the instructions in the GitHub readme file or below:
- Click here to Download the unpacked Chrome extension
- Open Chrome and open this URL
chrome://extensions
- Enable
Developer mode
(top-right corner) - Click on the Load unpacked button (top-left corner)
- Select the unzipped extension folder from Step 1 β All done!
- Click the
W
icon ofWordle Solved
extension to check the guess. You may also find today’s guess already filled (SPOILER)
wordle-solved-cli Coz why not?!#
I didn’t stop there, hehe β went ahead and built a CLI using create-node-cli, which tries to mimic the same UI in the terminal for all y’all terminal junkies like me. Install it globally npm i -g wordle-solved-cli
and then run wordle
anywhere. Woohoo! π₯³
Okay, I guess this is enough over-engineering for one day. Have fun solving Wordle with these tiny little automation tools. Use your code for good. I’d love to have you learn automation with me via NodeCLI.com.
P.S. SPOILERS in the tools but not in the post. Please do NOT spoil the fun of this fantastic game for anyone.
Developers Takeaway
Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!