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's explanation for the DC algorithm:
Download file here.
I based myself on
DC Algorithm (Click to View)
(11-21-2015, 12:09 PM)A-Man Wrote: [ -> ]1-Open the file for reading and store what's inside into a variable (or stream it, whatever you prefer/have available). The content of the file is gibberish (because it's encrypted).
2-Skip over the first one hundred and twenty three characters and start going through all characters in the file. Since counting in computers starts from 0, this means you will start from the 124rd letter character (index 123).
3-For every character you go through, convert it to its ASCII code, subtract from it the ASCII code of the Nth character in the key "odBearBecauseHeIsVeryGoodSiuHungIsAGo" (yes, the letters are shifted because there is a caeser cipher step we can skip with using this shifted key).
4- N is an index in the key which keeps increasing for every character and restarts back to 0 when it reaches the end of the key.
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.