04-15-2016, 07:22 PM
In response to someone's attempt to read a LF2 data file in JavaScript, I made a simple HTML page for this purpose.
I based myself on @A-Man's explanation for the DC algorithm:
Download file here.
I based myself on @A-Man's explanation for the DC algorithm:
DC Algorithm (Click to View)
Code:
<!DOCTYPE html>
<html>
<head>
<title>LF2 - Data Reader</title>
<meta charset="UTF-8" />
<meta name="description" content="LF2 data files reader.">
<meta name="keywords" content="LF2, DC , data, algorithm, file, files, decypher">
<meta name="author" content="MangaD">
<link rel="shortcut icon" href="http://www.lf-empire.de/favicon.ico" type="image/x-icon">
<style type="text/css">
html, body {
height:100%;
width:100%;
border:0;
margin:0;
padding: 0;
text-align:center;
}
#main {
margin-top:30px;
text-align:initial;
display:inline-block;
}
#DCode {
width:600px;
height:400px;
}
</style>
<script type="text/javascript">
var file;
function fileSupport() {// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
}
function openFile() {
file = document.getElementById("fileInput").files[0];
var fileName = escape(file.name);
var fileType = (file.type ? file.type : 'n/a');
var fileSize = file.size;
var lastModified = file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() : 'n/a';
if(file.name.substring(file.name.lastIndexOf(".")) != ".dat" ) {
alert('LF2 data file only.');
return false;
}
else {
fileType = "LF2/data";
}
document.getElementById('details').innerHTML =
'<strong>' + fileName + '</strong> (' + fileType + ') - ' +
fileSize + ' bytes, last modified: ' + lastModified;
return true;
}
function decrypt() {
var key = "odBearBecauseHeIsVeryGoodSiuHungIsAGo";
var reader = new FileReader();
reader.onload = function(){
var data = reader.result;
var text = "";
for (var i = 123, j = 0; i < data.length; i++, j++)
text += String.fromCharCode(data.charCodeAt(i) - key.charCodeAt(j%key.length));
document.getElementById('DCode').innerHTML = text;
};
reader.readAsBinaryString(file);
}
</script>
</head>
<body onload="fileSupport();">
<div id="main">
<label for="fileInput">Open .dat file:</label>
<br>
<input id="fileInput" type="file" onchange="if(openFile()) decrypt();">
<br>
<output id="details"></output>
<br>
<textarea id="DCode" wrap='off'></textarea>
</div>
</body>
</html>
Download file here.