-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.ts
56 lines (50 loc) · 1.27 KB
/
2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as fs from "fs";
import * as iconvlite from "iconv-lite";
var encoding = require("encoding");
function readFileSync_encoding(
filename: string | number | Buffer | import("url").URL,
encoding: string
) {
const content = fs.readFileSync(filename);
return iconvlite.decode(content, encoding);
}
let md5 = "";
let cap = "";
const Solved = new Set();
readFileSync_encoding("good.txt", "win1251")
.replace(/\[|\]/gm, "")
.replace(/\},/gm, "}\n")
.replace(/}\s?\n{/gm, "}|{")
.split("|")
.map(elem => {
Solved.add({
md5: elem
.match(/"md5":"(.*?)"/)[1]
.toString()
.trim(),
// tslint:disable-next-line:object-literal-sort-keys
cap: elem
.match(/"cap":"(.*?)"/)[1]
.toString()
.trim(),
});
});
let towrite = JSON.stringify([...Solved]);
readFileSync_encoding("badSolveFromList.txt", "win1251")
.replace(/}\s?\n{/gm, "}|{")
.split("|")
.map(elem => {
md5 = elem
.match(/"md5":"(.*?)"/)[1]
.toString()
.trim();
cap = elem
.match(/"cap":"(.*?)"/)[1]
.toString()
.trim();
const sSearch = `{"md5":"${md5}","cap":"${cap}"}`;
const r = new RegExp(sSearch, "g");
towrite = towrite.replace(r, "").replace(/\,\,/gm, ",");
});
var result = encoding.convert(towrite, "WINDOWS-1251", "UTF-8");
fs.writeFileSync("new.txt", result);