@@ -60,7 +60,7 @@ function foc(s){
6060if ( typeof addcredits == 'function' ) addcredits ( "ui.js" , 2.0 , "crashdemons" , "JXlate UI script and overarching operations." )
6161var oForm = null ;
6262var mode = 0 ;
63- var mode_bases = [ 256 , 'mc' , 2 , 8 , 10 , 16 , '32r' , '32h' , '32c' , 64 , 85 , 'ue' , 'ucs2' , 'utf8' ] ; //values used internally to represent each base in shorthand.
63+ var mode_bases = [ 256 , 'mc' , 2 , 8 , 10 , 16 , '32r' , '32h' , '32c' , 64 , 85 , 'ue' , 'ucs2' , 'utf8' , 'n' ] ; //values used internally to represent each base in shorthand.
6464//var mode_names=['Text','Morse','Binary','Octal','Decimal','Hexadecimal','Base32Rfc','Base32Hex','Base32Ckr','Base64','Ascii85','UrlEncode'];//unused array
6565
6666function xlate_bytesNF ( s , baseFrom ) { //translate a string from one base to another
@@ -102,7 +102,9 @@ function xlate_poll(){//poll the UI for mode radio-box changes.
102102 xlate_switch ( oldmode , newmode ) ; //trigger a translation
103103 } catch ( e ) {
104104 setMode ( oldmode ) ;
105- alert ( "This value could not be converted as specified.\nPlease make sure it is valid." )
105+ alert ( "This value could not be converted as specified.\nPlease make sure it is valid.\n\n"
106+ + "Technical Reason: \n" + " " + e
107+ )
106108 }
107109 console . log ( "conversion complete" ) ;
108110 }
@@ -1508,7 +1510,7 @@ fill_bases();
15081510function fill_bases ( ) { for ( var b = 32 ; b >= 0 ; b -- ) base_charsets [ b ] = b32hex . substr ( 0 , b ) . split ( "" ) ; } //set some charset options for use in conversion functions.
15091511
15101512//check if the base ID is a numeral conversion or an encoding (external function)
1511- function isEncodedBase ( base ) { return ( base === "32r" || base === "32h" || base === "32c" || base === 64 || base === 85 || base === "mc" || base === "ue" || base === "ucs2" || base === "utf8" ) ; }
1513+ function isEncodedBase ( base ) { return ( base === "32r" || base === "32h" || base === "32c" || base === 64 || base === 85 || base === "mc" || base === "ue" || base === "ucs2" || base === "utf8" || base === "n" ) ; }
15121514
15131515
15141516//resolves any encodings before regular numeral conversions.
@@ -1528,6 +1530,7 @@ function array_prepareEncodings(a,baseFrom,baseTo){
15281530 else if ( baseFrom === "mc" ) s = morse_decode ( a ) ;
15291531 else if ( baseFrom === "ucs2" ) s = convert_encoding ( a [ 0 ] , 'ucs2' , 'iso88591' ) ;
15301532 else if ( baseFrom === "utf8" ) s = convert_encoding ( a [ 0 ] , 'utf8' , 'iso88591' ) ;
1533+ else if ( baseFrom === "n" ) s = array_base2base ( a , radix_prompt ( ) , 256 ) . join ( "" ) ;
15311534 a = s . split ( "" ) ; //decode the single BaseX entry into chars (base256)
15321535 baseFrom = 256 ; //set up the parameter for the char->numeral array conversion.
15331536 }
@@ -1543,11 +1546,19 @@ function array_prepareEncodings(a,baseFrom,baseTo){
15431546 else if ( baseTo === "mc" ) a = [ morse_encode ( s ) ] ;
15441547 else if ( baseTo === "ucs2" ) a = [ convert_encoding ( s , 'iso88591' , 'ucs2' ) ] ;
15451548 else if ( baseTo === "utf8" ) a = [ convert_encoding ( s , 'iso88591' , 'utf8' ) ] ;
1549+ else if ( baseTo === "n" ) a = array_base2base ( a , 256 , radix_prompt ( ) ) ;
15461550 baseFrom = baseTo ; //we've encoded this to the new base, so lets set From to the current state - which disables any base conversion in array_base2base
15471551 }
15481552
15491553 return [ a , baseFrom , baseTo ] ; //output modified parameters.
15501554}
1555+ function radix_prompt ( ) {
1556+ var n = prompt ( "Please enter the radix (base) to convert with. (only 2-32 supported)" , "" ) ;
1557+ if ( n === null ) throw "no entry" ;
1558+ n = parseInt ( n ) ;
1559+ if ( n < 2 || n > 32 ) throw "invalid radix" ;
1560+ return n ;
1561+ }
15511562function array_base2base ( a , baseFrom , baseTo ) { //convert arrays of numerals from one base to another - implements support for Base64
15521563 var params = array_prepareEncodings ( a , baseFrom , baseTo ) ; //resolves any encodings before regular numeral conversions.
15531564 a = params [ 0 ] ; //our prep function returns the parameters as an array after it's done, let's get them back where they need to be.
0 commit comments