Skip to content
Advertisement

Tag: encoding

Why is my decryption function not working?

I created a function to encrypt and decrypt messages. the encrypting works fine. but when I try to log encrypted Hello World! it just logs H. Fixed it, i edited the encoding system to place a – between chars and the decoding system to just split the message at – and check if the element starts with c n or

Converting from a Uint8Array to a string and back

I’m having an issue converting from a particular Uint8Array to a string and back. I’m working in the browser and in Chrome which natively supports the TextEncoder/TextDecoder modules. If I start with a simple case, everything seems to work well: const uintArray = new TextEncoder().encode(‘silly face demons’); // Uint8Array(17) [115, 105, 108, 108, 121, 32, 102, 97, 99, 101, 32,

Why are atob and btoa not reversible

I’m trying to find a simple way to record and temporarily obfuscate answers to “quiz” questions I’m writing in Markdown. (I’ll tell the students the quiz answers during the presentation, so I’m not looking for any kind of secure encryption.) I thought I could use atob(‘message I want to obfuscate’) then tell students they can use btoa() in their developer

Using Javascript’s atob to decode base64 doesn’t properly decode utf-8 strings

I’m using the Javascript window.atob() function to decode a base64-encoded string (specifically the base64-encoded content from the GitHub API). Problem is I’m getting ASCII-encoded characters back (like ⢠instead of ™). How can I properly handle the incoming base64-encoded stream so that it’s decoded as utf-8? Answer The Unicode Problem Though JavaScript (ECMAScript) has matured, the fragility of Base64, ASCII,

Equivalent JavaScript functions for Python’s urllib.parse.quote() and urllib.parse.unquote()

Are there any equivalent JavaScript functions for Python’s urllib.parse.quote() and urllib.parse.unquote()? The closest I’ve come across are encodeURI()/encodeURIComponent() and escape() (and their corresponding un-encoding functions), but they don’t encode/decode the same set of special characters as far as I can tell. Answer OK, I think I’m going to go with a hybrid custom set of functions: Encode: Use encodeURIComponent(), then

Advertisement