Created
          June 13, 2013 10:40 
        
      - 
      
- 
        Save meeDamian/5772803 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var Teleport = function() {}; | |
| Teleport._rixits = "0123456789" | |
| + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| + "abcdefghijklmnopqrstuvwxyz" | |
| + "-_"; | |
| Teleport.numberToHash = function( n ) { | |
| if( isNaN(Number(n)) || n===null || n===Number.POSITIVE_INFINITY || n<0 ) throw "The input is not valid"; | |
| n = Math.floor( n ); | |
| var result = ''; | |
| do result = this._rixits.charAt(n%64) + result; | |
| while( n=Math.floor(n/64) ); | |
| return result; // String | |
| }; | |
| Teleport.hashToNumber = function( h ) { | |
| if(typeof h==="undefined") return false; | |
| for(var i=0, result=0; i<h.length; i++) result = (result*64) + this._rixits.indexOf(h.charAt(i)); | |
| return result; // Integer | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment