@borfast/arrispwgen
Advanced tools
| export declare function generate(date: Date, seed?: string): string; | ||
| export declare class InvalidDateRangeError extends Error { | ||
| constructor(); | ||
| } | ||
| export declare function generate_multi(startDate: Date, endDate: Date, seed?: string): { | ||
| date: Date; | ||
| password: string; | ||
| }[]; | ||
| export declare const DEFAULT_SEED = "MPSJKMDHAI"; |
| export declare const _DEFAULT_SEED = "MPSJKMDHAI"; | ||
| export declare const _TABLE1: number[][]; | ||
| export declare const _TABLE2: number[][]; | ||
| export declare const _ALPHANUM: string[]; |
| export declare function list1(date: Date): number[]; | ||
| export declare function list2(seed: string): number[]; | ||
| export declare function num8(l3: number[]): number; | ||
| export declare function list3(l1: number[], l2: number[]): number[]; | ||
| export declare function list4(l3: number[]): number[]; | ||
| export declare function list5(seed: string, l4: number[]): number[]; | ||
| export declare function indexers(date: Date, seed: string): number[]; |
+30
-34
@@ -1,36 +0,32 @@ | ||
| import { _ALPHANUM, _DEFAULT_SEED } from './constants.js'; | ||
| import { indexers } from './data.js'; | ||
| export function generate(date) { | ||
| var seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _DEFAULT_SEED; | ||
| var idx = indexers(date, seed); | ||
| var password_of_the_day = []; | ||
| var len = idx.length; | ||
| for (var i = 0; i < len; i++) { | ||
| password_of_the_day[i] = _ALPHANUM[idx[i]]; | ||
| } | ||
| return password_of_the_day.join(''); | ||
| import { _ALPHANUM, _DEFAULT_SEED } from "./constants.js"; | ||
| import { indexers } from "./data.js"; | ||
| export function generate(date, seed = _DEFAULT_SEED) { | ||
| const idx = indexers(date, seed); | ||
| const passwordOfTheDay = []; | ||
| const len = idx.length; | ||
| for (let i = 0; i < len; i++) { | ||
| passwordOfTheDay[i] = _ALPHANUM[idx[i]]; | ||
| } | ||
| return passwordOfTheDay.join(''); | ||
| } | ||
| export function generate_multi(startdate, enddate) { | ||
| var seed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _DEFAULT_SEED; | ||
| if (startdate > enddate) { | ||
| throw 'The start date must precede the end date.'; | ||
| } | ||
| var days = 1 + Math.ceil((enddate - startdate) / (1000 * 60 * 60 * 24)); | ||
| var password_list = []; | ||
| var date = startdate; | ||
| for (var i = 0; i < days; i++) { | ||
| var this_date = new Date(new Date(date).setDate(date.getDate() + i)); | ||
| password_list.push({ | ||
| 'date': this_date, | ||
| 'password': generate(this_date, seed) | ||
| }); | ||
| } | ||
| return password_list; | ||
| export class InvalidDateRangeError extends Error { | ||
| constructor() { | ||
| super('The start date must precede the end date.'); | ||
| } | ||
| } | ||
| export var DEFAULT_SEED = _DEFAULT_SEED; | ||
| export function generate_multi(startDate, endDate, seed = _DEFAULT_SEED) { | ||
| if (startDate > endDate) { | ||
| throw new InvalidDateRangeError(); | ||
| } | ||
| const days = 1 + Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)); | ||
| const passwordList = []; | ||
| for (let i = 0; i < days; i++) { | ||
| const date = new Date(new Date(startDate).setDate(startDate.getDate() + i)); | ||
| passwordList.push({ | ||
| 'date': date, | ||
| 'password': generate(date, seed) | ||
| }); | ||
| } | ||
| return passwordList; | ||
| } | ||
| export const DEFAULT_SEED = _DEFAULT_SEED; |
+23
-4
@@ -1,4 +0,23 @@ | ||
| export var _DEFAULT_SEED = 'MPSJKMDHAI'; | ||
| export var _TABLE1 = [[15, 15, 24, 20, 24], [13, 14, 27, 32, 10], [29, 14, 32, 29, 24], [23, 32, 24, 29, 29], [14, 29, 10, 21, 29], [34, 27, 16, 23, 30], [14, 22, 24, 17, 13]]; | ||
| export var _TABLE2 = [[0, 1, 2, 9, 3, 4, 5, 6, 7, 8], [1, 4, 3, 9, 0, 7, 8, 2, 5, 6], [7, 2, 8, 9, 4, 1, 6, 0, 3, 5], [6, 3, 5, 9, 1, 8, 2, 7, 4, 0], [4, 7, 0, 9, 5, 2, 3, 1, 8, 6], [5, 6, 1, 9, 8, 0, 4, 3, 2, 7]]; | ||
| export var _ALPHANUM = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; | ||
| export const _DEFAULT_SEED = 'MPSJKMDHAI'; | ||
| export const _TABLE1 = [ | ||
| [15, 15, 24, 20, 24], | ||
| [13, 14, 27, 32, 10], | ||
| [29, 14, 32, 29, 24], | ||
| [23, 32, 24, 29, 29], | ||
| [14, 29, 10, 21, 29], | ||
| [34, 27, 16, 23, 30], | ||
| [14, 22, 24, 17, 13] | ||
| ]; | ||
| export const _TABLE2 = [ | ||
| [0, 1, 2, 9, 3, 4, 5, 6, 7, 8], | ||
| [1, 4, 3, 9, 0, 7, 8, 2, 5, 6], | ||
| [7, 2, 8, 9, 4, 1, 6, 0, 3, 5], | ||
| [6, 3, 5, 9, 1, 8, 2, 7, 4, 0], | ||
| [4, 7, 0, 9, 5, 2, 3, 1, 8, 6], | ||
| [5, 6, 1, 9, 8, 0, 4, 3, 2, 7] | ||
| ]; | ||
| export const _ALPHANUM = [ | ||
| '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', | ||
| 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', | ||
| 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' | ||
| ]; |
+54
-67
@@ -1,80 +0,67 @@ | ||
| import { _TABLE1, _TABLE2 } from './constants.js'; | ||
| import { _TABLE1, _TABLE2 } from "./constants.js"; | ||
| export function list1(date) { | ||
| // Last two digits of the year | ||
| var year = parseInt(date.getFullYear().toString(10).substr(2, 2), 10); // Number of the month. The month in a Date object is zero-indexed, | ||
| // i.e., January == 0, so we add 1 to satisfy the algorithm. | ||
| var month = date.getMonth() + 1; | ||
| var day_of_month = date.getDate(); // Day of the week. Normally 0 would be Sunday but we need it to be Monday. | ||
| var day_of_week = date.getDay() - 1; | ||
| if (day_of_week < 0) { | ||
| day_of_week = 6; | ||
| } | ||
| var list1 = []; | ||
| for (var i = 0; i <= 4; i++) { | ||
| list1[i] = _TABLE1[day_of_week][i]; | ||
| } | ||
| list1[5] = day_of_month; | ||
| if (year + month - day_of_month < 0) { | ||
| list1[6] = (year + month - day_of_month + 36) % 36; | ||
| } else { | ||
| list1[6] = (year + month - day_of_month) % 36; | ||
| } | ||
| list1[7] = (3 + (year + month) % 12) * day_of_month % 37 % 36; | ||
| return list1; | ||
| // Last two digits of the year | ||
| const year = parseInt(date.getFullYear().toString(10).substr(2, 2), 10); | ||
| // Number of the month. The month in a Date object is zero-indexed, | ||
| // i.e., January == 0, so we add 1 to satisfy the algorithm. | ||
| const month = date.getMonth() + 1; | ||
| const dayOfMonth = date.getDate(); | ||
| // Day of the week. Normally 0 would be Sunday but we need it to be Monday. | ||
| let dayOfWeek = date.getDay() - 1; | ||
| if (dayOfWeek < 0) { | ||
| dayOfWeek = 6; | ||
| } | ||
| const list1Result = []; | ||
| for (let i = 0; i <= 4; i++) { | ||
| list1Result[i] = _TABLE1[dayOfWeek][i]; | ||
| } | ||
| list1Result[5] = dayOfMonth; | ||
| if (((year + month) - dayOfMonth) < 0) { | ||
| list1Result[6] = (((year + month) - dayOfMonth) + 36) % 36; | ||
| } | ||
| else { | ||
| list1Result[6] = ((year + month) - dayOfMonth) % 36; | ||
| } | ||
| list1Result[7] = (((3 + ((year + month) % 12)) * dayOfMonth) % 37) % 36; | ||
| return list1Result; | ||
| } | ||
| export function list2(seed) { | ||
| var list2 = []; | ||
| for (var i = 0; i <= 7; i++) { | ||
| list2[i] = seed.charCodeAt(i) % 36; | ||
| } | ||
| return list2; | ||
| const list2Result = []; | ||
| for (let i = 0; i <= 7; i++) { | ||
| list2Result[i] = (seed.charCodeAt(i)) % 36; | ||
| } | ||
| return list2Result; | ||
| } | ||
| export function num8(l3) { | ||
| return l3[8] % 6; | ||
| return l3[8] % 6; | ||
| } | ||
| export function list3(l1, l2) { | ||
| var list3 = []; | ||
| for (var i = 0; i <= 7; i++) { | ||
| list3[i] = (l1[i] + l2[i]) % 36; | ||
| } | ||
| list3[8] = (list3[0] + list3[1] + list3[2] + list3[3] + list3[4] + list3[5] + list3[6] + list3[7]) % 36; | ||
| list3[9] = Math.round(Math.pow(num8(list3), 2)); | ||
| return list3; | ||
| const list3Result = []; | ||
| for (let i = 0; i <= 7; i++) { | ||
| list3Result[i] = (((l1[i] + l2[i])) % 36); | ||
| } | ||
| list3Result[8] = (list3Result[0] + list3Result[1] + list3Result[2] + list3Result[3] + list3Result[4] + list3Result[5] + list3Result[6] + list3Result[7]) % 36; | ||
| list3Result[9] = Math.round(Math.pow(num8(list3Result), 2)); | ||
| return list3Result; | ||
| } | ||
| export function list4(l3) { | ||
| var list4 = []; | ||
| for (var i = 0; i <= 9; i++) { | ||
| list4[i] = l3[_TABLE2[num8(l3)][i]]; | ||
| } | ||
| return list4; | ||
| const list4Result = []; | ||
| for (let i = 0; i <= 9; i++) { | ||
| list4Result[i] = l3[_TABLE2[num8(l3)][i]]; | ||
| } | ||
| return list4Result; | ||
| } | ||
| export function list5(seed, l4) { | ||
| var list5 = []; | ||
| for (var i = 0; i <= 9; i++) { | ||
| list5[i] = (seed.charCodeAt(i) + l4[i]) % 36; | ||
| } | ||
| return list5; | ||
| const list5Result = []; | ||
| for (let i = 0; i <= 9; i++) { | ||
| list5Result[i] = (seed.charCodeAt(i) + l4[i]) % 36; | ||
| } | ||
| return list5Result; | ||
| } | ||
| export function indexers(date, seed) { | ||
| var l1 = list1(date); | ||
| var l2 = list2(seed); | ||
| var l3 = list3(l1, l2); | ||
| var l4 = list4(l3); | ||
| return list5(seed, l4); | ||
| } | ||
| const l1 = list1(date); | ||
| const l2 = list2(seed); | ||
| const l3 = list3(l1, l2); | ||
| const l4 = list4(l3); | ||
| return list5(seed, l4); | ||
| } |
+17
-14
| { | ||
| "name": "@borfast/arrispwgen", | ||
| "version": "4.0.2", | ||
| "version": "5.0.0", | ||
| "description": "Arris Password of the Day Generator reusable library", | ||
@@ -18,6 +18,7 @@ "keywords": [ | ||
| "author": "Raúl Santos (https://www.borfast.com)", | ||
| "main": "lib/arrispwgen.js", | ||
| "main": "./lib/arrispwgen.js", | ||
| "type": "module", | ||
| "files": [ | ||
| "/lib" | ||
| "/lib", | ||
| "./lib/arrispwgen.d.ts" | ||
| ], | ||
@@ -29,16 +30,18 @@ "repository": { | ||
| "scripts": { | ||
| "build": "babel -d lib src/", | ||
| "watch": "babel --watch -d lib src/", | ||
| "test": "jest", | ||
| "prepublishOnly": "npm run build" | ||
| "build": "ttsc --project tsconfig.json", | ||
| "prepublishOnly": "npm run build", | ||
| "lint": "eslint -c .eslintrc.cjs 'src/**/*.{ts,tsx}' '__tests__/**/*.{ts,tsx}'", | ||
| "pretest": "npm run lint", | ||
| "test": "jest" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/cli": "*", | ||
| "@babel/core": "*", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.9.0", | ||
| "@babel/preset-env": "*", | ||
| "@jest/globals": "^25.5.2", | ||
| "babel-jest": "^25.3.0", | ||
| "eslint": "*", | ||
| "jest": "*" | ||
| "@types/jest": "^25.2.1", | ||
| "@typescript-eslint/parser": "^2.31.0", | ||
| "@zoltu/typescript-transformer-append-js-extension": "^1.0.1", | ||
| "eslint": "^6.8.0", | ||
| "jest": "^26.0.1", | ||
| "ts-jest": "^25.4.0", | ||
| "ttypescript": "^1.5.10", | ||
| "typescript": "^3.8.3" | ||
| }, | ||
@@ -45,0 +48,0 @@ "engines": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
10477
17.18%9
50%142
49.47%9
12.5%1
Infinity%