Posts

Showing posts from March, 2025

Sieve of Eratosthenes optimization

Image
       In cybersecurity, ancient algorithms still hold power. The Sieve of Eratosthenes , a prime number finder, underpins modern cryptography . This seemingly simple method, especially with stack optimizations, is fundamental. It acts as a base for complex cryptographic algorithms like Euler's theorem ( a^ φ ( n ) ≡ 1 ( mod n ) ) .      Prime numbers are vital in public-key encryption . Eratosthenes' Sieve aids in generating primes for systems like RSA . Euler's function, key in cryptography, relies on prime factorization , where the Sieve is crucial.      Understanding these basics is essential in cybersecurity. This simple algorithm reveals how math grounds our security. #include <iostream> using namespace std; bool vec[ 1000001], m=0; int n, X=0, i; int main() {     cin>>n;     i=2;     while(i*i<n-X+1)     {         if(vec[i]==0)       ...