TinyUrlShortenerServiceApp is a simple console application to make an URL shortener
A bijective function is necessary to find an inverse function g('abc') = 123 for our f(123) = 'abc' function.
We can start from a simple alphabet to use. For example the alphabet: [a-zA-Z0-9]. It contains 62 letters. We can take an auto-generated, unique numerical key (the auto-incremented id of a SQL table for example).
For this example, I will use 12510 (125 with a base of 10).
Now you have to convert 12510 to X62 (base 62).
12510 = 2×621 + 1×620 = [2,1]
This requires the use of integer division and modulo. A pseudo-code example:
digits = []
while num > 0 remainder = modulo(num, 62) digits.push(remainder) num = divide(num, 62)
digits = digits.reverse Now map the indices 2 and 1 to your alphabet. This is how your mapping (with an array for example) could look like:
0 → a 1 → b ... 25 → z ... 52 → 0 61 → 9 With 2 → c and 1 → b, you will receive cb62 as the shortened URL.
Use these instructions to get the project up and running.
You will need the following tools:
Follow these steps to get your development environment set up:
- Clone the repository
- At the root directory, restore required packages by running:
dotnet restore
- Next, build the solution by running:
dotnet build
- Next, launch the console application by running:
dotnet run --project TinyUrlShortenerServiceApp <"your identifier to convert">
If you launch the console application by running:
dotnet run --project TinyUrlShortenerServiceApp 123456789
then you'll see the following output:
Encoded URL: cbsd5j
Decoded URL: 123456789
TinyUrlShortenerServiceApp has only 1 project;
- TinyUrlShortenerServiceApp
- Interfaces
- Services
This folder contains the contract of the application service injected into the TinyUrlShortenerServiceApp.
This folder contains the implementation of the application service injected into the TinyUrlShortenerServiceApp.
The application's main starting point is the .NET Core console project. This is a classical console application, with a public static void Main method in Program.cs. It uses the Nuget package "Microsoft.Extensions.DependencyInjection" to set up Microsoft’s dependency injection container.
- .NET Core 3.1
- .NET Core Native DI
Thanks to the following people who have contributed to this project:
If you want to contact me you can reach me at daniele.crivello84@libero.it.
This project uses the following license: MIT.