TinyUrl bidirectional function

Integer to character and vice-versa

Implement two method that used in tiny url generation and parsing, first method will convert string to number and second one is convert same number to string.
Number to String Algorithm:
  1. Set char_base = 26
  2. Set char_map = “abc…zABC..Z01..9”
  3. Create output_string
  4. Iterate till number is greater than zero
    1. add output_string += char_map.charAg(number % char_map)
  5. reverse output_string
  6. return output_string
String to Number Algorithm:
  1. Set char_base = 26
  2. Set char_map = “abc…zABC..Z01..9”
  3. Set number = 0
  4. Iterate from 0 to string.length
    1. number += string.charAt(i) * char_base ^ (string.length - (index + 1))
  5. Return number

Source Code:
Github: TinyUrl.java


Output:

Tiny url:  irm9P
Id: 122312215    
Author: Hrishikesh Mishra