This is simply a matter of performing base conversion. Simply convert the long to the appropriate numeric base, corresponding to the number of characters in your string, and use the range string as your set of "digits".
For example, suppose you have the string "0123456789ABCDEF", then this means you must convert to base 16, hexadecimal. If the string is "01234567", then you convert to base 8, octal.
result = "";
while (number > 0)
{
result = range[(number % range.length)] + result;
number = number / 16; //integer division, decimals discarded
}
For going back, take the first character, find its position in the string, and add it to the result. Then, for each subsequent character, multiply the current result by the base before adding the position of the next character.
result = 0;
for (int i = 0; i < input.length; i++)
{
result = result * range.length;
result = range.indexOf(input[i])
}