Skip to content

Commit

Permalink
支持直接编写GLSL代码作为filter
Browse files Browse the repository at this point in the history
  • Loading branch information
TransparentLC committed Sep 29, 2024
1 parent 9c5207d commit e65b6c9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@
<p>根据 GPU 性能和占用率调节这两个值。</p>
<p>你会得到一个生效时间距离现在 {{ (backTime > 2592000) ? `${Math.ceil(backTime / 2592000)} 个月` : `${Math.ceil(backTime / 86400)} 天` }}之内(最早为 <code>{{ (new Date(Date.now() - backTime * 1000)).toISOString() }}</code>)的密钥。</p>
<div class="form-group">
<label>密钥指纹格式</label>
<label>密钥指纹格式 <a @click="showAutoFilter">查看 GLSL 代码</a></label>
<input v-model="pattern" type="text" required style="font-variant-ligatures:none">
<input v-model="vanitySubkey" type="checkbox">将格式应用到子密钥而不是主密钥上
</div>
<p>40 个十六进制数字,不区分大小写。空格会被忽略,<code>X</code> 表示只要这些位相同即可,其他 <code>[\dA-FX]</code> 以外的字符表示对该位数字没有要求。</p>
<p>最后 <input v-model="patternLength" style="width:3em;padding:unset;text-align:center" type="number" min="1" max="40"> 个数字为 <input v-model="patternNumber" style="width:1em;padding:unset;text-align:center" type="text" pattern="[\dA-Fa-fXx]"> <a @click="patternHelper">快速设置</a></p>
<p>预计需要计算 {{ estimatedHashCount }} 次 hash,实际的计算次数可能是这个值的几分之一或几倍,也许需要一点运气……</p>
<details style="margin-bottom:var(--global-line-height)">
<summary>直接使用 GLSL 代码!</summary>
<div class="terminal-card" style="margin-bottom:var(--global-line-height)">
<textarea v-model="filter" style="border:none" rows="5"></textarea>
</div>
<p>你可以自行编写更复杂的判断密钥指纹是否符合格式的 GLSL 代码,这些代码将以 `#define FILTER(h) (code)` 的形式出现在算号使用的着色器中。</p>
<p>换行会被替换成空格,留空则会使用“密钥指纹格式”的设定,输入错误的代码将无法得到任何密钥。</p>
<p>在着色器中,计算的密钥指纹(实际上是 80 bytes 的 SHA-1 hash)以大端序保存为 `uint[5]`,并使用上面的 `FILTER` 来检查是否符合格式。</p>
</details>
<details style="margin-bottom:var(--global-line-height)">
<summary>把不同密钥的“靓号”合并到一起!</summary>
<div class="grid desktop-only">
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"preview": "vite preview"
},
"devDependencies": {
"@types/node": "^22.2.0",
"@types/node": "^22.7.4",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.5.4",
"vite": "^5.4.0",
"typescript": "^5.6.2",
"vite": "^5.4.8",
"vite-plugin-html": "^3.2.2"
},
"dependencies": {
Expand Down
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SecretSubkeyPacket,
} from 'openpgp/lightweight';
import { TarWriter } from '@gera2ld/tarjs';
import { createVanityKey } from './vanity-key.ts';
import { patternToFilter, createVanityKey } from './vanity-key.ts';
import tadaData from './tada.ogg?inline';
import silenceData from './near-silence.ogg?inline';
import {
Expand Down Expand Up @@ -35,6 +35,7 @@ const app: {
pattern: string,
patternNumber: string,
patternLength: number,
filter: string,
vanitySubkey: boolean,
notification: {
sfx: boolean,
Expand All @@ -59,6 +60,7 @@ const app: {
mounted: () => void,
addUserID: () => void,
patternHelper: () => void,
showAutoFilter: () => void,
toggleKeygen: () => Promise<void>,
bulkDownload: () => Promise<void>,
subkeyCombine: () => Promise<void>,
Expand All @@ -74,6 +76,7 @@ const app: {
pattern: '',
patternNumber: '0123456789ABCDEFXXXX'[Math.floor(Math.random() * 20)],
patternLength: 6 + Math.floor(Math.random() * 3),
filter: '',
vanitySubkey: false,
notification: {
sfx: false,
Expand Down Expand Up @@ -126,6 +129,10 @@ const app: {
this.pattern = this.formatFingerprint(('*'.repeat(40 - this.patternLength) + this.patternNumber.repeat(this.patternLength)));
},

showAutoFilter() {
alert(patternToFilter(this.pattern));
},

async bulkDownload() {
if (!this.generatedKeyHistory.length) return;
const tar = new TarWriter;
Expand Down Expand Up @@ -178,7 +185,7 @@ const app: {
do {
const generatedKey = await createVanityKey(
options,
this.pattern,
this.filter.replaceAll('\n', ' ') || patternToFilter(this.pattern),
this.thread,
this.iteration,
(h, t) => {
Expand Down
23 changes: 12 additions & 11 deletions src/vanity-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ const swap32 = (x: number) => (
((x >> 24) & 0xFF)
) >>> 0;

export const createVanityKey = async (
config: GenerateKeyOptions,
pattern: string,
thread: number,
iteration: number,
progressCallback: (hash: number, time: DOMHighResTimeStamp) => void = () => {},
checkAbort: (hash: number, time: DOMHighResTimeStamp) => boolean = () => false,
vanitySubkey: boolean = false,
): Promise<KeyPair | undefined> => {
export const patternToFilter = (pattern: string) => {
pattern = pattern.replaceAll(' ', '');
if (pattern.length != 40) throw new Error('Invalid pattern');
const filter = [
return [
...[0, 8, 16, 24, 32].map((e, i) => {
const s = pattern.substring(e, e + 8);
let mask = '';
Expand Down Expand Up @@ -86,8 +78,17 @@ export const createVanityKey = async (
return acc;
}, [] as string[]),
].filter(Boolean).join(' && ') || 'true';
// console.log(filter);
}

export const createVanityKey = async (
config: GenerateKeyOptions,
filter: string,
thread: number,
iteration: number,
progressCallback: (hash: number, time: DOMHighResTimeStamp) => void = () => {},
checkAbort: (hash: number, time: DOMHighResTimeStamp) => boolean = () => false,
vanitySubkey: boolean = false,
): Promise<KeyPair | undefined> => {
const size = Math.round(Math.sqrt(thread));
const canvas = new OffscreenCanvas(size, size);
const gl = canvas.getContext('webgl2')!;
Expand Down

0 comments on commit e65b6c9

Please sign in to comment.