2024-01-26 15:50:07 +00:00
|
|
|
// encryptor.js
|
|
|
|
// HIGHT(ISO/IEC 18033-3) encryption and decryption tool for WelsonJS
|
|
|
|
// Namhyeon Go <abuse@catswords.net>
|
|
|
|
// https://github.com/gnh1201/welsonjs
|
|
|
|
|
|
|
|
var FILE = require("lib/file");
|
|
|
|
var Toolkit = require("lib/toolkit");
|
|
|
|
|
|
|
|
function main(args) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
console.error("Usage: cscript app.js encryptor <filename>");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-03-19 09:00:08 +00:00
|
|
|
var filename = args[0];
|
2024-03-19 08:59:34 +00:00
|
|
|
var dstfile = filename + ".enc";
|
|
|
|
if (FILE.fileExists(dstfile)) {
|
|
|
|
console.error(dstfile, "already exists. Please delete it.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-26 15:50:07 +00:00
|
|
|
var userKey = '';
|
|
|
|
while (userKey.length == 0 || userKey.length > 16) {
|
|
|
|
userKey = Toolkit.prompt("Please enter the password for encryption:");
|
|
|
|
}
|
2024-03-19 08:59:34 +00:00
|
|
|
|
2024-01-30 09:28:54 +00:00
|
|
|
var data = FILE.readFile(filename, FILE.CdoCharset.CdoUTF_8);
|
2024-01-26 15:50:07 +00:00
|
|
|
var encryptedData = Toolkit.encryptStringHIGHT(userKey, data);
|
|
|
|
|
|
|
|
var dstfile = filename + ".enc";
|
2024-01-30 09:28:54 +00:00
|
|
|
FILE.writeFile(dstfile, encryptedData, FILE.CdoCharset.CdoUTF_8);
|
2024-01-26 15:50:07 +00:00
|
|
|
console.log("Saved to", dstfile);
|
|
|
|
|
|
|
|
console.log("Done");
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.main = main;
|