When encrypting string using xor encryption, things work well. But when dealing with bytes, it does not work for. It throws error at k.charCodeAt(0)
Please what could be the problem? This is my full code.
function Main() {
var key;
key = "thisistheencryptionkey";
WScript.Echo("Encryption started . . .");
Crypt( "C:\\xxx\\xxx\\file.exe", "C:\\xxx\\xxx\\fileenc.txt", key );
WScript.Echo("Decryption started . . .");
Crypt( "C:\\xxx\\xxx\\fileenc.txt", "C:\\xxx\\xxx\\file.exe", key );
WScript.Echo("Finished!");}
function Crypt(fileIn, fileOut, key) {
var fileInRead, objFSOFile;
objFSOFile = new ActiveXObject( "Scripting.FileSystemObject" );
var e = objFSOFile.getFile(fileIn);
var fileSize = e.size;
key = key;
while (key.length < fileSize) {
key += key;
}
var adTypeBinaryWrite = 1;
var adSaveCreateOverWrite = 2;
var BinaryStreamWrite;
BinaryStreamWrite = new ActiveXObject("ADODB.Stream");
BinaryStreamWrite.Type = adTypeBinaryWrite;
BinaryStreamWrite.Open();
var adTypeBinary = 1;
var BinaryStream;
BinaryStream = new ActiveXObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.LoadFromFile(fileIn);
var k, ss, q;
i = 0;
do {
q = key.substr(i, 1);
k = BinaryStream.Read(1);
ss = q.charCodeAt(0);
BinaryStreamWrite.Write(String.fromCharCode(k.charCodeAt(0) ^ ss));
i = i + 1;
} while (!BinaryStream.EOS);
BinaryStream.close();
BinaryStreamWrite.SaveToFile(fileOut, adSaveCreateOverWrite);
BinaryStreamWrite.close();}
EDIT: Error says: Object expected ERROR Code: 800A138F
After testing out a lot of things that didn't work,this is what worked for me and it's implementation.