Below is some VB Script - I can't figure out how to convert it to javascript. Below that, I've put my best attempt at as far as I got - can anyone help me out correcting and completing it?
Thanks,
Iain
The VB Script: -
const BASE_64_MAP_INIT ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-
dim arrBase64EncMap(63)
-
dim arrBase64DecMap(127)
-
strNewLine = "<P>" & vbCRLF
-
for iLoop = 0 to len(BASE_64_MAP_INIT) - 1
-
arrBase64EncMap(iLoop) = mid(BASE_64_MAP_INIT, iLoop + 1, 1)
-
next
-
for iLoop = 0 to len(BASE_64_MAP_INIT) - 1
-
arrBase64DecMap(ASC(arrBase64EncMap(iLoop))) = iLoop
-
next
-
-
public function base64Encode(strPlain)
-
if len(strPlain) = 0 then
-
base64Encode = ""
-
exit function
-
end if
-
-
'** Work out rounded down multiple of 3 bytes length for the unencoded text **
-
iBy3 = (len(strPlain) \ 3) * 3
-
strReturn=""
-
-
'** For each 3x8 byte chars, covert them to 4x6 byte representations in the Base64 map **
-
iIndex = 1
-
do while iIndex <= iBy3
-
iFirst = asc(mid(strPlain, iIndex+0, 1))
-
iSecond = asc(mid(strPlain, iIndex+1, 1))
-
iiThird = asc(mid(strPlain, iIndex+2, 1))
-
strReturn = strReturn & arrBase64EncMap((iFirst \ 4) AND 63 )
-
strReturn = strReturn & arrBase64EncMap(((iFirst * 16) AND 48) + ((iSecond \ 16) AND 15 ) )
-
strReturn = strReturn & arrBase64EncMap(((iSecond * 4) AND 60) + ((iiThird \ 64) AND 3 ) )
-
strReturn = strReturn & arrBase64EncMap(iiThird AND 63)
-
iIndex = iIndex + 3
-
loop
-
-
'** Handle any trailing characters not in groups of 3 **
-
'** Extend to multiple of 3 characters using = signs as per RFC **
-
if iBy3 < len(plain) then
-
iFirst = asc(mid(strPlain, iIndex+0, 1))
-
strReturn = strReturn & arrBase64EncMap((iFirst \ 4) AND 63 )
-
if (len(strPlain) MOD 3 ) = 2 then
-
iSecond = asc(mid(strPlain, iIndex+1, 1))
-
strReturn = strReturn & arrBase64EncMap(((iFirst * 16) AND 48) + ((iSecond \ 16) AND 15 ) )
-
strReturn = strReturn & arrBase64EncMap((iSecond * 4) AND 60)
-
else
-
strReturn = strReturn & arrBase64EncMap((iFirst * 16) AND 48)
-
strReturn = strReturn & "="
-
end if
-
strReturn = strReturn & "="
-
end if
-
-
'** Return the encoded result string **
-
base64Encode = strReturn
-
end function
-
My attempt at javascript : -
var BASE_64_MAP_INIT ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
-
var arrBase64EncMap = new Array(63);
-
var arrBase64DecMap = new Array(127);
-
-
for (var i = 0; i < BASE_64_MAP_INIT.length; i++) {
-
arrBase64EncMap[i] = BASE_64_MAP_INIT.charAt(i);
-
}
-
for (var i = 0; i < BASE_64_MAP_INIT.length; i++) {
-
arrBase64DecMap[ASC(arrBase64EncMap[i]] = i
-
arrBase64DecMap[arrBase64EncMap[i].charCodeAt(0)] = i
-
}
-
-
function base64Encode(strPlain) {
-
if (strPlain.length == 0) {
-
return "";
-
}
-
-
// Work out rounded down multiple of 3 bytes length for the unencoded text
-
iBy3 = strPlain.length - (strPlain.length % 3);
-
var strReturn = "";
-
-
// For each 3x8 byte chars, covert them to 4x6 byte representations in the Base64 map
-
var iIndex = 1;
-
while (iIndex <= iBy3) {
-
var iFirst = strPlain.charCodeAt(iIndex+0);
-
var iSecond = strPlain.charCodeAt(iIndex+1);
-
var iiThird = strPlain.charCodeAt(iIndex+2);
-
-
//**** i'm totall lost here - what's the AND doing, and how do I do it in JS? ****//
-
var strReturn += arrBase64EncMap((iFirst - (iFirst % 4) AND 63);
-
1 2298
Heya, iporter. Welcome to TSDN!
Are you getting an error? Is the code not doing what you want it to?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Davis |
last post by:
When I create new documents in Dreamweaver, there are several choices for
ASP creation:
ASP JavaScript: run at client side??
ASP VBScript: run at server side??
ASP.NET C#
ASP.NET VB
I don't...
|
by: Christopher Brandsdal |
last post by:
If I have a .ASP page that runs JScript code - is it possible to include an
..ASP page that runs VBscript???
|
by: Bill |
last post by:
I need to convert a variable, nNum, into a two-character string. nNum is
always less than 100.
If nNum is 0, the string needs to be "00", if it's 1, it needs to be "01",
if it's 34, it needs to...
|
by: davidgordon |
last post by:
Hi,
I have some pages with this VBScript code, which obviously does not
work in Firefox. How can I convert this to Javascript in order for my
web page to work in Firefox ? It basically fills a...
|
by: darcykahle |
last post by:
Is there any way of converting an existing access form into html
format? The form in question has built-in visual-basic code, which
gets commented out when you use the "save as" method, instead of...
|
by: thinktwice |
last post by:
in my script file , i need call a method of a atl com
module(implemented in vc++), which returan an safearray. i don't know
how to convert it into array in jscript. i have tried serveral ways to...
|
by: rishabhshrivastava |
last post by:
Hello All,
How can I convert a value to Double in JavaScript??? In vbscript i
believe its done as
cDbl(Value)
I tried lots of way but getting a value of "NaN".
Any suggestions/ideas will...
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I convert a Number into a String with
exactly 2 decimal places?...
|
by: sathyan8294 |
last post by:
what is websites for convert javascript to vbscript?
|
by: murugavelmsc |
last post by:
Hi,
i have a javascript code. I want to convert into VBscript.
pls
help me
Javascript Code:
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |