Ahmad Awais

NAVIGATE


SHARE


Wordle Solved: Reverse Engineering and Hacking Wordle

Ahmad AwaisAhmad Awais

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

Reverse 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. ๐Ÿฅณ

Wordle Solution

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"]

Wordle Solution List

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 Ahmad Awais#

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...)

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!

Wordle Solved Chrome Extension

You can read the instructions in the GitHub readme file or below:

  1. Click here to Download the unpacked Chrome extension
  2. Open Chrome and open this URL chrome://extensions
  3. Enable Developer mode (top-right corner)
  4. Click on the Load unpacked button (top-left corner)
  5. Select the unzipped extension folder from Step 1 โ€” All done!
  6. Click the W icon of Wordle 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! ๐Ÿฅณ

Wordle Solved CLI

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.

Helping businesses build developer-led adoption for 10+ yrs.
VP of Developer Relations (DevRel, DX Eng., Dev Content Docs) at RapidAPI. I'm Hiring!

๐Ÿ“Ÿ Edutainer at Node.js CLI Automation course (100 videos ยท 22 Projects) & VSCode.pro course (over 26K devs). ๐ŸŽฉ Award-winning Open Source Engineer & Dev Advocate ๐ŸฆŠ Google Developers Expert Web DevRel ๐Ÿš€ Mars Ingenuity Helicopter code contributor ๐Ÿ† 8th GitHub Stars Award recipient ๐ŸŒณ Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator.

โœŒ๏ธ Author of various open-source dev-tools and software libraries used by millions of developers worldwide โ“ฆ WordPress Core Developer ๐Ÿ“ฃ TEDx Speaker with 100+ international talks.

๐Ÿ”ฅ Satya Nadella ยท CEO of Microsoft, said โ€” Awais is an awesome example for developers.
๐Ÿ™Œ Leading developers and publishing technical content for over a decade ๐Ÿ’œ Loves his wife (Maedah) โฏ Read more about Ahmad Awais.

๐Ÿ‘‹โ€ฆ Awais is mostly active on Twitter @MrAhmadAwais

๐Ÿ“จ

Developers Takeaway

Takeaway my professional opinion on open-source, developer relations, growing your business with family, and everything in between! Delivered to your inbox a couple of times every year. I'm even funny at times. I hate spam โ€” pinky-promise!

๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ‘ฉโ€๐Ÿ’ป 168,174 Developers Already Subscribed
Comments 0
There are currently no comments.