This is a program to decrypt some text from a file. A button allows the user to select a file from an Open Dialog Box. Upon selection, the contents will be displayed in the input textarea.
Please ignore the modules "readByLine" and "readKeyword" below as there are some problems.
Not sure if HTML5 supports in Chrome 20.0.1132.47 m and IE7.
Attaching the code as below:
<html>
<head>
<script type="text/javascript">
//Select a Cipher file from Open Dialog Box
function readCipherFile()
{
if (!window.FileReader)
document.getElementById("cipher").innerHTML = "<p>This browser doesn\'t support File API</p>";
else
{
// Input handler for cipher text
document.getElementById("cipherfile").onchange = function() {
readFileAsText(this.files[0]);
};
}
}
//Read content as text and display in Input textarea
function readFileAsText(file)
{
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event) {
document.getElementById("cipher").innerHTML = event.target.result;
};
reader.onerror = function() {
document.getElementById("cipher").innerHTML = 'Unable to read ' + file.fileName;
};
}
//Select a Keyword file from Open Dialog Box
function readKeyword()
{
if (!window.FileReader)
document.getElementById("keyword").innerHTML = "<p>This browser doesn\'t support File API</p>";
else
{
// Input handler for keyword
document.getElementById("keyfile").onchange = function() {
readByLine(this.files[0]);
};
}
}
//Read and display one keyword at a time
function readByLine(file)
{
var reader = new FileReader();
var arr = "";
console.log("test" + arr);
console.log(file);
reader.onload = function(event) {
arr = event.target.result;
};
reader.readAsText(file);
for(i=0; i<arr.length; i++)
{
arr = arr.split("\n");
document.getElementById("keyword").value = arr;
}
//display the next keyword when button is clicked
var keyButton = document.getElementById("keyfile");
keyButton.addEventListener("click", readByLine, false);
}
</script>
</head>
<body>
<center>
<h2>Vigenere Cipher</h2>
<br>
<form name="form1">
<table>
<tr>
<td>
Input:
</td>
<td>
<textarea name=input id="cipher" rows=10 cols=60 wrap=virtual></textarea>
</td>
</tr>
<tr>
<td></td>
<td align="center">
<input type=file id="cipherfile" onClick="readCipherFile(this)" />
</td>
</tr>
<tr height="20px"></tr>
<tr>
<td>
Key:
</td>
<td>
<textarea name=key id="keyword" rows=2 cols=60 wrap=virtual></textarea>
</td>
<tr>
<td></td>
<td align="center">
<input type=file id="keyfile" onClick="readKeyword()" />
</td>
</tr>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<input type=button value="Decrypt" onClick="decode()" style="margin-left: 135px">
</td>
</tr>
<td>
Output:
</td>
<td>
<textarea id="output" rows=10 cols=60 wrap=virtual></textarea>
</td>
</table>
</form>
</center>
</body>
<html>