Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active September 19, 2024 07:31
Show Gist options
  • Save SomajitDey/5e5c7e6ce18ce59e740b6d73e646c71b to your computer and use it in GitHub Desktop.
Save SomajitDey/5e5c7e6ce18ce59e740b6d73e646c71b to your computer and use it in GitHub Desktop.
Any data can be compressed using URL shorteners. Two such compression can form a public-private key pair. Only one can lead to the other not the other way round.

Compression

  • take your minified JSON and turn it into a URL safe base64 string. The length of this string can be as big as this.
  • make a dummy url like http://dummy.tld/<the base64 string> and shorten it using any URL shortener.
  • save the unique path of the shortened url as your compressed data (henceforth called token). No need to store the domain of the shortened URL as the URL shortener would be hardcoded in your app.

Decompression

  1. Reconstruct the shortened URL from the token. Try to fetch (GET) the shortened URL.
  2. Parse the response for the redirect url and extract the base64 string.
  3. Decode the base64.

Cryptography

  1. Compress public key and get the token.
  2. Compress {"private":<private-key>, "public":<public-key-token>} and get the token.

Note: private-key-token leads to public-key, but not the other way round!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment