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.

Founder & CEO at Langbase.com Β· Ex VP DevRel Rapid Β· Google Developers Advisory Board (gDAB) founding member. πŸ§‘β€πŸ’» AI/ML/DevTools Angel Investor ❯ AI/ML Advisory Board member San Francisco, DevNetwork

🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel πŸš€ NASA Mars Ingenuity Helicopter mission code contributor πŸ† 8th GitHub Stars Award recipient with 3x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. πŸ“Ÿ Teaching thousands of developers Node.js CLI Automation (100 videos Β· 22 Projects) & VSCode.pro course. Over 142 Million views, 22 yrs Blogging, 56K developers learning, 200+ FOSS.

✌️ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide ⓦ WordPress Core Developer πŸ“£ TEDx Speaker with 100+ international talks.

✨ As quoted by: Satya Nadella Β· CEO of Microsoft β€” 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

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!

✨ 172,438 Developers Already Subscribed
Comments 0
There are currently no comments.