Skip to content

README's generatePrime(_ width: Int) performances #85

@nathanfallet

Description

@nathanfallet

The README's generatePrime(_ width: Int) function is very slow for big numbers (can take up to 10s to generate two primes for a RSA key)

func generatePrime(_ width: Int) -> BigUInt {
    while true {
        var random = BigUInt.randomInteger(withExactWidth: width)
        random |= BigUInt(1)
        if random.isPrime() {
            return random
        }
    }
}

Any way to generate primes quicker?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions