I would build a HTA "ASCII to HEX to Unicode Converter Utility" Thanks to these functions written in javascript from this site
Ok This is quite simple i build into HTA with Javascript Functions and it works as a charm !
But my aim is to translate these functions written in javascript to Vbscript and here is my tries :
"ASCII to HEX to Unicode Converter Utility with Javascript"
Code: Select all
<html>
<head>
<title>ASCII to HEX to Unicode Converter Utility</title>
<HTA:APPLICATION ICON="Explorer.exe" ID="bbceditor" APPLICATIONNAME="Converter Tool" WINDOWSTATE="maximize">
<link rel="stylesheet" media="screen" type="text/css" title="design_encoder" />
<script language="javascript" type="text/javascript">
<!--
function decode(){
if(document.forms[0].hex.value != ''){
var vText = document.forms[0].hex.value;
document.forms[0].ascii.value = unescape(vText);
}
}
function encode(){
if(document.forms[0].ascii.value != ''){
var vText = document.forms[0].ascii.value;
document.forms[0].hex.value = convertToHex(vText);
var vEncoded = convertToUnicode(vText);
document.forms[0].unicode.value = vEncoded;
document.getElementById("unicodeHTML").innerHTML = vEncoded;
document.forms[0].ascii.focus();
document.forms[0].ascii.blur();
document.forms[0].ascii.select();
}
}
function convertToUnicode(source) {
result = '';
for (i=0; i<source.length; i++)
result += '&#' + source.charCodeAt(i) + ';';
return result;
}
function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++)
hex += "%" + num.charCodeAt(i).toString(16).toUpperCase();
return hex;
}
function convertToASCII() {
if (document.forms[0].unicode.value != '') {
var uniText = document.forms[0].unicode.value;
var testText = uniText.substring(2,uniText.length-1).split(";&#")
var resultString = ""
for (i=0;i<testText.length;i++)
resultString += "%" + dec2hex(testText<em>)
document.forms[0].ascii.value = unescape(resultString);
}
}
function dec2hex(n){
var hex = "0123456789ABCDEF";
var mask = 0xf;
var retstr = "";
while(n != 0){
retstr = hex.charAt(n&mask) + retstr;
n>>>=4;
}
return retstr.length == 0 ? "0" : retstr;
}
</script>
</head>
<body>
<center><h1>ASCII Converter</h1>
<p>
A utility to convert ASCII characters to Hexadecimal and Unicode
</p>
<form name="blah" action="">
<br/>
<b><font color="white">ASCII Text:</font></b><br/>
<input type="text" name="ascii" size="75" />
<input type="button" value="Encode" onclick="encode()" />
<br/><br/><br/>
<b><font color="white">Hex Value:</font></b><br/>
<input type="text" name="hex" size="75" />
<input type="button" value="Decode Hex to ASCII" onclick="decode()" />
<br/><br/><br/>
<b><font color="white">Unicode Value:</font></b><br/>
<input type="text" name="unicode" size="75" />
<input type="button" value="Decode Unicode to ASCII" onclick="convertToASCII()" />
<b><font color="white">Unicode will display in HTML as : </font><font color="Red"><span id="unicodeHTML"></span></font></b>
<br/><br/><br/>
<input type="reset" value="Clear" onclick="document.getElementById('unicodeHTML').innerHTML = ''" />
</form></body>
</html>
Code: Select all
<html>
<head>
<title>ASCII to HEX to Unicode Converter Utility</title>
<HTA:APPLICATION ICON="Explorer.exe" ID="bbceditor" APPLICATIONNAME="Converter Tool" WINDOWSTATE="maximize">
<link rel="stylesheet" media="screen" type="text/css" title="design_encoder" />
<script language="Vbscript" type="text/Vbscript">
<!--
Sub decode()
Dim vText
If document.forms[0].hex.value <> "" then
vText = document.forms[0].hex.value
document.forms[0].ascii.value = unescape(vText)
end if
End Sub
Sub encode()
Dim vText,Vencoded
If document.forms[0].ascii.value <> "" Then
vText = document.forms[0].ascii.value
document.forms[0].hex.value = convertToHex(vText)
vEncoded = convertToUnico
de(vText)
document.forms[0].unicode.value = vEncoded
document.getElementById("unicodeHTML").innerHTML = vEncoded
document.forms[0].ascii.focus()
document.forms[0].ascii.blur()
document.forms[0].ascii.select()
End If
End Sub
function convertToUnicode(source)
result = ""
For i=0 To Unbound(source.length)
result = "&#" & source.charCodeAt(i) & ";"
return result
Next
End Function
function convertToHex(num)
hex = ""
For (i=0 To Unbound(num.length)
hex = "%" & num.charCodeAt(i).toString(16).toUpperCase()
return hex
Next
End Function
function convertToASCII()
if document.forms[0].unicode.value <> "" Then
uniText = document.forms[0].unicode.value
testText = uniText.substring(2,uniText.length-1).split(";&#")
resultString = ""
for i=0 To unbound(testText.length
resultString = "%" & dec2hex(testText<em>)
document.forms[0].ascii.value = unescape(resultString)
Next
End If
End Function
function dec2hex(n)
hex = "0123456789ABCDEF"
mask = 0xf
retstr = ""
while(n <> 0) do
retstr = hex.charAt(n&mask) & retstr
n>>>=4
loop
return retstr.length = 0 ? "0" : retstr
End Function
</script>
</head>
<body>
<center><h1>ASCII Converter</h1>
<p>
A utility to convert ASCII characters to Hexadecimal and Unicode
</p>
<form name="blah" action="">
<br/>
<b><font color="white">ASCII Text:</font></b><br/>
<input type="text" name="ascii" size="75" />
<input type="button" value="Encode" onclick="encode()" />
<br/><br/><br/>
<b><font color="white">Hex Value:</font></b><br/>
<input type="text" name="hex" size="75" />
<input type="button" value="Decode Hex to ASCII" onclick="decode()" />
<br/><br/><br/>
<b><font color="white">Unicode Value:</font></b><br/>
<input type="text" name="unicode" size="75" />
<input type="button" value="Decode Unicode to ASCII" onclick="convertToASCII()" />
<b><font color="white">Unicode will display in HTML as : </font><font color="Red"><span id="unicodeHTML"></span></font></b>
<br/><br/><br/>
<input type="reset" value="Clear" onclick="document.getElementById('unicodeHTML').innerHTML = ''" />
</form></body>
</html>
Thank you for any help !