# .---------------------------------------[ icedragon@quickfox.org ]--. # # | base95.py | base95 Number Conversion Module (c) 2006 by IceDragon | # # |-------------------------------------------------------------------| # # | This module contains functions to translate base95 numbers used | # # | by Furcadia into decimal numbers and vice-versa. The length of | # # | each is limited by the system restrictions, no more. | # # `-------------------------------------------------------------------' # ###--# stoi #--### def stoi ( string ): """Convert a base95 string into its numeric representation.""" length = len( string ) num = 0 mult = 1 while length > 0: num += ( ord(string[length - 1]) - 32 ) * mult mult *= 95 length -= 1 return num ###--# itos #--### def itos ( num ): """Convert a number into its base95 representation.""" string = '' while num > 0: string = chr( (num % 95) + 32 ) + string num /= 95 return string ###--# END OF FILE #--###