atob() issue

atob() and btoa() is not working properly.

by Joy George Kunjikkuru

HTML

<script src="http://dase.googlecode.com/svn/trunk/www/js/webtoolkit.base64.js"></script>
<button id="addUnicodeButton" onClick="addUnicode()" title="Add hard coded unicode string 'ജോയ് മോൻ' to the input">Click to add unicode text to input text area.Then click on atob button to see error</button>
<button id="getFromGithubAPIButton" onClick="getFromGithubAPI()" title="Get data from https://api.github.com/repos/joymon/joyful-visualstudio/readme">Click to get base64 encoded data from github API</button>
<hr/>
<textarea id="inputText">Sample input</textarea>
<hr/>Operations
<button onClick="atob_btoa_Test()" title="Converts the text in input to base64 and converts back">btoa and atob</button>
<button onClick="btoaTest()">btoa</button>
<button onClick="atobTest()">atob</button>
<br/>
<button onClick="btoaBase64Test()">btoa</button>
<button onClick="atobBase64Test()">atob</button>
<br/>
<button onClick="btoaBase64JSTest()">btoa Base64.js</button>
<button onClick="atobBase64JSTest()">atob Base64.js</button>

JavaScript

function addUnicode() {
    document.getElementById('inputText').value = "ജോയ് മോൻ";
}

function getFromGithubAPI() {
    url = "https://api.github.com/repos/joymon/joyful-visualstudio/readme";
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var myArr = JSON.parse(xmlhttp.responseText);
            document.getElementById('inputText').value = myArr.content;
        }

    };
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
}

function btoaTest() {
    var input = document.getElementById('inputText').value;
    //debugger;
    executeWithTryCatch(function () {
        var encoded = btoa(input);
        document.getElementById('inputText').value = encoded;
    });
}

function atobTest() {
    executeWithTryCatch(function () {
        var decoded = atob(document.getElementById('inputText').value);
        document.getElementById('inputText').value = decoded;
    });
}

function btoaBase64Test() {
    executeWithTryCatch(function () {
        var inputText = document.getElementById('inputText');
        encoded = btoa(unescape(encodeURIComponent(inputText.value)));
        document.getElementById('inputText').value = encoded
    });
}

function atobBase64Test() {
    executeWithTryCatch(function () {
        var inputText = document.getElementById('inputText');
        decoded = decodeURIComponent(escape(atob(inputText.value)));
        document.getElementById('inputText').value = decoded
    });
}

function atob_btoa_Test() {
    var input = document.getElementById('inputText').value;
    //debugger;
    try {
        var encoded = btoa(input);
        alert(encoded);
        var decoded = atob(encoded)
        alert(decoded);
    } catch (ex) {
        alert(ex);
    }
}

function btoaBase64JSTest() {
    executeWithTryCatch(function () {
        var inputText = document.getElementById('inputText');
        encoded = Base64.encode(inputText.value);
...