In order to manage our list of shortened strings and their corresponding hashes we are going to use a database. The encoding schema to be used by this shortening algorithm will be Base 62 encoding, as we are going to use 62 letters. ![]() This leads us to certain filtering operations for the input string prior to calculating the hash, but that’s just a matter of programmatic effort that we can handle later on. Thus, there must not exist more than one hash for the same original string and the encoding operation must be deterministic. Of course to achieve this bi-directional property, we need to be able to retrieve the original string based on the hash calculated and additionally, we must be given the same hash for the same string on every attempt. This is an examplary long string to be shortened T4Xza Let’s have a look at the following example string and the (possible) shortened outcome: URL) and a hash:įurthermore, we want this unique hash to be (much) shorter than the original string. What we want to achieve is a unique bi-directional mapping of a given string (e.g. Prior to discussing the source code let’s first break down the theory behind the shortening algorithm using Base 62 encoding. ![]() This article presents a simple but effective template for creating a custom string shortening service, based a on proven and widely used algorithm – Base 62 encoding. Thus, a vast range of projects have evolved aiming to implement custom string (URL) shortening solutions. ![]() Although they are very handy when it comes to shortening URLs in blog posts and articles oftentimes they can’t be used in proprietary software due to certain copyright and usage restrictions. Today, there already exist numerous URL shortening services, such as tinyurl, bit.ly, qr.cx and many more.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |