views:

168

answers:

2

Why doesn't the javascript output anything? It should output some html code.

<html>
<head>
<script type="text/javascript"><!--`

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function d64(input) {
    var output = new StringMaker();
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    while (i < input.length) {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output.append(String.fromCharCode(chr1));

        if (enc3 != 64) {
            output.append(String.fromCharCode(chr2));
        }
        if (enc4 != 64) {
            output.append(String.fromCharCode(chr3));
        }
    }

    return output.toString();
}

//-->
</script>

</head>
<body>
blah
<script type="text/javascript">document.write(d64("PGEgaHJlZj0ibWFpbHRvOnN0ZXZlbkBtYWlsaW5hdG9yLmNvbSI+c3RldmVuQG1haWxpbmF0b3IuY29tPC9hPg=="));</script><noscript>steven[|at|]mailinator[|dot|]com</noscript>
blah
@
@
@
@
@
@
@
@
@@@@@22</body>
</html>
+1  A: 

StringMaker is not defined:

function d64(input) {
    var output = new StringMaker(); //<= what's this?
    ...
}
Jerome
The code works on: http://rumkin.com/tools/compression/base64.php
steven
you need the <script language="JavaScript" src="/inc/js/browser_faster.js">
steven
it is defined in browser_faster.js
Jerome
A: 

I am getting a javascript error. StringMaker is undefined. But StringMaker relates to Java ?

Shoban
You're confusing with StringBuilder or StringBuffer.
Jerome