Skip to content

Commit

Permalink
Updated sanitizing for unsigned integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvov1 committed Sep 16, 2024
1 parent 63e736c commit 28d56bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Binary file modified sanitize/primes.bin
100755 → 100644
Binary file not shown.
40 changes: 22 additions & 18 deletions sanitize/unsigned/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::vector<primeType> loadPrimes(const std::filesystem::path& fromLocation) {
if(input.fail())
throw std::runtime_error("Failed to open prime table");

const std::size_t primesAmount = 2000; //std::filesystem::file_size(fromLocation) / sizeof(primeType);
const std::size_t primesAmount = std::filesystem::file_size(fromLocation) / sizeof(primeType);
std::vector<unsigned short> primes (primesAmount);
for (auto& prime: primes)
input.read(reinterpret_cast<char*>(&prime), sizeof(primeType));
Expand All @@ -27,29 +27,33 @@ std::vector<primeType> loadPrimes(const std::filesystem::path& fromLocation) {
}

int main() {
const Aeu<512> n = "0x4c6f0a38f6c296d07052b794a02317ce9758855";
std::cout << "N = " << std::showbase << std::hex << n << std::endl;

const std::filesystem::path primesLocation = "../../primes.bin";
const auto primes = loadPrimes(primesLocation);

Aeu<512> base = 2u;
Aeu<2048> power = 1u;
std::array numbers = { Aeu<512>("0x4c6f0a38f6c296d07052b794a02317ce9758855"), // 0xa9ab4314cf -> 2 × 3^2 × 7 × 1181 × 2083 × 2351
Aeu<512>("0x14cd01a38ac5c55992acb21ff9665294b30f9ee578393dad147") }; // 0x2fdd8d6ba69 -> 2^3 × 3 × 5 × 647 × 2203 × 19231

for(auto& number: numbers) {
std::cout << "N = " << std::showbase << std::hex << number << std::endl;

Aeu<512> base = 2u;
Aeu<4096> power = 1u;

for(unsigned short prime : primes) {
const auto primeF = static_cast<long double>(prime),
boarder = static_cast<long double>(std::numeric_limits<uint64_t>::max());
const auto primePower = static_cast<long double>(static_cast<uint64_t>(std::log(boarder) / std::log(primeF)) - 1);
for(unsigned short prime : primes) {
const auto primeF = static_cast<long double>(prime),
boarder = static_cast<long double>(std::numeric_limits<uint64_t>::max());
const auto primePower = static_cast<long double>(static_cast<uint64_t>(std::log(boarder) / std::log(primeF)) - 1);

power *= static_cast<uint64_t>(std::pow(primeF, primePower));
if(power.bitCount() > 1536) {
base = Aeu<512>::powm<2048>(base, power, n);
power = 1u;
power *= static_cast<uint64_t>(std::pow(primeF, primePower));
if(power.bitCount() > 3072) {
base = Aeu<512>::powm<4096>(base, power, number);
power = 1u;

const auto candidate = Aeu<512>::gcd(base - 1u, n);
if(candidate > 1u) {
std::cout << "Completed: " << std::showbase << std::hex << candidate << std::endl;
return 0;
const auto candidate = Aeu<512>::gcd(base - 1u, number);
if(candidate > 1u) {
std::cout << "Completed: " << std::showbase << std::hex << candidate << std::endl;
break;
}
}
}
}
Expand Down

0 comments on commit 28d56bd

Please sign in to comment.