mtcute/packages/core/tests/prime-factorization.spec.ts

24 lines
931 B
TypeScript
Raw Normal View History

2021-04-08 12:19:38 +03:00
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { hexDecodeToBuffer, hexEncode } from '@mtcute/tl-runtime'
import { factorizePQSync } from '../src/utils/crypto/factorization.js'
2021-04-08 12:19:38 +03:00
describe('prime factorization', function () {
this.timeout(10000) // since PQ factorization relies on RNG, it may take a while (or may not!)
it('should decompose PQ to prime factors P and Q', () => {
const testFactorization = (pq: string, p: string, q: string) => {
const [p1, q1] = factorizePQSync(hexDecodeToBuffer(pq))
expect(hexEncode(p1)).eq(p.toLowerCase())
expect(hexEncode(q1)).eq(q.toLowerCase())
2021-04-08 12:19:38 +03:00
}
// from samples at https://core.telegram.org/mtproto/samples-auth_key
testFactorization('17ED48941A08F981', '494C553B', '53911073')
// random example
testFactorization('14fcab4dfc861f45', '494c5c99', '494c778d')
})
})