From 1382ebd104f73adcc346ff90065cde908caca148 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Fri, 21 Nov 2025 18:35:34 +0800 Subject: [PATCH] dasdasd --- .../src/tools/card/CardGeneratorTool.ts | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/browser-automation-ts/src/tools/card/CardGeneratorTool.ts b/browser-automation-ts/src/tools/card/CardGeneratorTool.ts index 2310372..1b1b6c9 100644 --- a/browser-automation-ts/src/tools/card/CardGeneratorTool.ts +++ b/browser-automation-ts/src/tools/card/CardGeneratorTool.ts @@ -143,12 +143,12 @@ export class CardGeneratorTool extends BaseTool { const rand = Math.random(); if (rand < 0.5) { - // 50% 权重生成(严格按照70张成功案例的统计规律) + // 50% 马尔可夫链生成(考虑位置关联性) return this.generateByWeights(selectedPrefix, digitsNeeded, length); } if (rand < 0.9) { // 40% 变异生成(从成功案例变异1-2位) - return this.generateByMutation(selectedPrefix, successfulPatterns || [], generation.mutationDigits || [1, 1], digitsNeeded, length); + return this.generateByMutation(selectedPrefix, successfulPatterns || [], generation?.mutationDigits || [1, 1], digitsNeeded, length); } // 10% 纯随机(保持多样性) } @@ -280,7 +280,7 @@ export class CardGeneratorTool extends BaseTool { } /** - * 基于统计权重生成卡号(60个成功案例的分布) + * 基于马尔可夫链生成卡号(考虑位置之间的关联性) * @param {string} prefix - BIN前缀 * @param {number} digitsNeeded - 需要生成的主体位数(不含校验位) * @param {number} totalLength - 卡号总长度 @@ -291,23 +291,33 @@ export class CardGeneratorTool extends BaseTool { return generateLuhnNumber(prefix, totalLength); } - // 基于70个真实成功案例的位置权重(后2位,不含校验位) - const positionWeights = [ - [12, 7, 10, 7, 8, 5, 5, 9, 6, 1], // 百位: 0占17.1% - [9, 7, 8, 3, 6, 7, 3, 10, 9, 8] // 十位: 7占14.3% - ]; - - if (digitsNeeded > positionWeights.length) { + if (digitsNeeded !== 2) { + // 如果不是2位,降级到纯随机 return generateLuhnNumber(prefix, totalLength); } - let pattern = ''; - for (let pos = 0; pos < digitsNeeded; pos++) { - const weights = positionWeights[pos]; - const digit = this.weightedRandomDigit(weights); - pattern += digit; - } - + // 第1位:百位的权重分布 + const firstDigitWeights = [12, 7, 10, 7, 8, 5, 5, 9, 6, 1]; + const firstDigit = this.weightedRandomDigit(firstDigitWeights); + + // 第2位:基于第1位的马尔可夫转移概率 + const markovTransitions: Record = { + '0': [3, 1, 1, 2, 0, 2, 1, 2, 0, 0], + '1': [0, 0, 2, 0, 1, 2, 0, 2, 0, 0], + '2': [2, 0, 0, 0, 1, 2, 0, 1, 4, 0], + '3': [0, 2, 2, 0, 0, 0, 1, 2, 0, 0], + '4': [1, 0, 1, 0, 3, 0, 0, 1, 1, 1], + '5': [0, 3, 1, 0, 0, 0, 0, 0, 1, 0], + '6': [1, 0, 0, 0, 1, 0, 0, 1, 1, 1], + '7': [1, 1, 1, 1, 0, 0, 1, 0, 2, 2], + '8': [1, 0, 0, 0, 0, 1, 0, 1, 0, 3], + '9': [0, 0, 0, 0, 0, 0, 0, 0, 0, 1] + }; + + const secondDigitWeights = markovTransitions[firstDigit] || [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]; + const secondDigit = this.weightedRandomDigit(secondDigitWeights); + + const pattern = firstDigit + secondDigit; const partial = prefix + pattern; const checkDigit = this.calculateLuhnCheckDigit(partial);