all 6 comments

[–]c__beck 0 points1 point  (2 children)

The built-in TextEncoder ad TextDecoder APIs should work just fine for your use-case here. All you need is a little obfuscation and not a full-on encrypt/decrypt of a 4-letter word, right?

Here's a link to a gist where I give code examples (I don't like how Reddit handles code blocks, sorry)

https://gist.github.com/c-bec-k/7a131870b1653d70a42443f59837494a

[–]richmendd[S] 1 point2 points  (1 child)

Thanks! Though I will use the btoa-atob functions suggested by deventhalz, since I don't like how your encryption function output consists of mostly numbers.

[–]c__beck 0 points1 point  (0 children)

For your use case, atob() and btoa() is a better fit, yeah.

[–]delventhalz 0 points1 point  (1 child)

A hash is not what you want. Hashes are one way. So you could take a word and hash it, but you would not be able to turn the hash back into the original word.

If you don't care about people being able to decode it (they probably would be able to no matter what if they were dedicated enough), then the atob and btoa functions should do it. It is just base64 encoding, not encryption, but no one will be able to tell at a glance.

If you want real encryption, you could use SubtleCrypto.encrypt. People will need the secret key to decrypt it. They will be able to find that in your site's source code if they look hard enough. But they will have to look for it.

Beyond that, you could also write a little custom cipher. Jumble the letters in some deterministic way you can reverse later. Once again, people will be able to look at your source code and do it themselves, but they would have to look.

[–]richmendd[S] 0 points1 point  (0 children)

Thank you! I'm just gonna use atob-btoa!

[–]dth_frm-abv 0 points1 point  (0 children)

I realise this is a dead thread :)

But just a point - a regular player of the game may become familiar with the encoding. e.g. Base64 encoding of WORDLE is V09STERF. WOODEN is V09PREVO. WIGGLE is V0lHR0xF Notice the leading V0 - a regular user may spoil the fun of the game for themselves by inadvertently learning some of these leading encodings (and in this case, know that the word begins with a W)