test: added factorization tests

This commit is contained in:
alina 🌸 2024-02-08 04:10:09 +03:00
parent cc5cb3150d
commit 809e794816
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { bigIntToBuffer, bufferToBigInt } from '../bigint-utils.js'
import { factorizePQSync } from './factorization.js'
import { defaultCryptoProviderFactory } from './index.js'
describe('prime factorization', () => {
const testFactorization = (pq: bigint, p: bigint, q: bigint) => {
const [p_, q_] = factorizePQSync(defaultCryptoProviderFactory(), bigIntToBuffer(pq))
expect(bufferToBigInt(p_)).toBe(p)
expect(bufferToBigInt(q_)).toBe(q)
}
it('should factorize', () => {
testFactorization(2090522174869285481n, 1112973847n, 1878321023n)
testFactorization(1470626929934143021n, 1206429347n, 1218991343n)
testFactorization(2804275833720261793n, 1555252417n, 1803100129n)
})
})