Created
November 6, 2010 06:29
-
-
Save mrdoob/665235 to your computer and use it in GitHub Desktop.
Simple encode/decode for Array of Numbers (6-bit)
This file contains 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
function decode( string ) { | |
var output = []; | |
string.split('').forEach( function ( v ) { output.push( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf( v ) ); } ); | |
return output; | |
} | |
function encode( array ) { | |
var output = ""; | |
array.forEach( function ( v ) { output += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt( v ); } ); | |
return output; | |
} | |
var data = [20, 20, 20, 0, 18, 18, 10, 2, 15, 30, 10, 5, 20, 20, 20, 1, 18, 18, 10, 2, 15, 30, 10, 10]; | |
var encoded = encode( data ); | |
var decoded = decode( encoded ); | |
console.log( data ); | |
console.log( encoded ); | |
console.log( decoded ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment