UNPKG

2ch-trip

Version:

2ch compatible trip generator

29 lines (28 loc) 1.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createRawKeyTrip = void 0; const unix_crypt_td_js_1 = __importDefault(require("unix-crypt-td-js")); /** * 生キートリップを生成する */ const createRawKeyTrip = (key) => { const saltSuffixString = '..'; const rawKey = key // 2 文字目以降の全ての文字列を取得 .substr(1) // 2 文字ごとに配列に分割する .match(/.{2}/g) // ASCII コードを ASCII 文字に変換する .map((hexadecimalASCIICode) => { const demicalASCIICode = parseInt(hexadecimalASCIICode, 16); return String.fromCharCode(demicalASCIICode); }) // 文字列にする .join(''); const salt = `${key}${saltSuffixString}`.substr(17, 2); return (0, unix_crypt_td_js_1.default)(rawKey, salt).substr(-10, 10); }; exports.createRawKeyTrip = createRawKeyTrip;