Socket
Socket
Sign inDemoInstall

@swapnil-pando/url-shortening

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @swapnil-pando/url-shortening

A URL shortener using SHA1 encryption with no external api


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
150 kB
Created
Weekly downloads
 

Readme

Source

Introduction

This is an implementation of a URL Shortener Implementation without use of any external API using SHA1 encryption

Original URL => SHA(Original URL) => 40 bits encrypted hash

We slice this 40 digits hash into 5 equal parts of 8 bits each, which is converted into decimal which again is base62 encoded.

Why base-62 encoding is needed ?

If we see the allowed characters in our shortened url i.e [A-Z], [a-z], [0-9], then it comes to 26 + 26 + 10 = 62 characters

We want our shortened url to be less than or equal to 7 characters. So 62^7, which is coming upto 35 billion urls.

Hence we used base-62 encoding here.

In this implementation, it is made sure that the same long url will always generate the same shortened url, unless until some randomness is wanted and is given as true in the parameter to the helper function.

Additional Implementation Details

A long-url to short-url mapping is stored in database with an expiry of 3 months for a record for redirection. Also a retry mechanism is implemented to check if a shortened url already exists in db, before inserting a shortened url. The retry count is set-up to 10.

Test Result

Repeats in a run of 1000000 are 99 with repeat percentage of 0.009899999999999999 Repeats in a run of 8500000 are 8416 with repeat percentage of 0.09901176470588235 Repeats in a run of 10000000 are 11725 with repeat percentage of 0.11725

Keywords

FAQs

Last updated on 26 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc