Change string to a new character set | Converts str to given character set ; hashing for new character set ; conversion of new character set ; Driver code
function conversion ( charSet , str ) { var n = str . length ; var hashChar = Array ( 26 ) ; for ( var i = 0 ; i < 26 ; i ++ ) { var ch = Math . abs ( charSet [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; hashChar [ ch ] = String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; } var s = " " ; for ( var i = 0 ; i < n ; i ++ ) s += ( hashChar [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ) ; return s ; } var charSet = " " . split ( ' ' ) ; var str = " " ; str = conversion ( charSet , str ) ; document . write ( str ) ;