CSE 2101 Lab Manual: Algorithms & Cryptography
CSE 2101 Lab Manual: Algorithms & Cryptography
Pseudo primes are composite numbers that satisfy the condition b^(n-1) ≡ 1 (mod n) for a base b, making them appear prime under specific tests. Carmichael numbers are a stronger type of pseudo prime, satisfying this property for all bases b that are coprime to n. This makes them deceptive since they pass Fermat's primality test for non-prime numbers.
The Euclidean algorithm finds the GCD of two integers through a series of division steps, using the remainder of each division as the new divisor in the next step, continuing until the remainder is zero. The last non-zero remainder is the GCD. It is highly efficient compared to other methods like prime factorization, as it operates in O(log(min(a, b))) time, leveraging the properties of division and modulus.
The RSA decryption key d is derived using the extended Euclidean algorithm to find the modular inverse of the encryption key e relative to φ(n), which is (p-1)(q-1). The relationship de ≡ 1 (mod φ(n)) ensures that the decryption and encryption operations are inverses. This derivation is critical to RSA's functionality and security, relying on the difficulty of reverse-engineering φ(n) without knowing p and q.
Binary search divides a sorted list into halves, reducing the possible location of the target element by half each iteration, performing O(log n) comparisons in the process. This efficiency is in stark contrast with linear search, which can require up to n comparisons in the worst case. Binary search is most efficient when dealing with very large sorted datasets where quick lookup times are crucial.
Cantor expansion expresses a number x as a sum x = an*n! + an-1*(n-1)! + ... + a1*1!, where each a is a digit within a specific range determined by the factorial factor. This is closely related to the factorial number system, where numbers are expressed similar to base-n systems but using factorials instead of powers. This method is useful in combinatorial contexts because it allows unique representation using constrained digits.
A linear congruential generator produces a sequence of pseudo-random numbers using the recurrence relation x_{n+1} = (ax_n + c) mod m, where x is the sequence, and a, c, and m are parameters setting up the sequence's linear characteristics. It is widely used due to its simplicity, but its randomness quality heavily depends on the parameter choices and initial seed, making mathematical analysis crucial for high-quality randomness.
The bubble sort algorithm compares each pair of adjacent elements and swaps them if they are in the wrong order, effectively "bubbling" the highest element to the end of the list in each pass. Its time complexity is O(n^2) in the worst and average cases. Insertion sort, on the other hand, builds the sorted array one element at a time and has a time complexity of O(n^2) as well, but it performs better than bubble sort on average for partially sorted arrays since it only scans as much as needed to place an element.
In RSA, modular arithmetic is crucial as it allows for operations over a finite field. Encryption transforms a message M into a ciphertext C using C = M^e mod n, and decryption recovers M using M = C^d mod n. The use of modulus n ensures that operations remain within a manageable size, even for large e and d, and roots the technique in number theory, which contributes both to the cryptosystem's functionality and its security.
The RSA encryption process involves choosing two large prime numbers, p and q, and computing their product n = pq. The totient φ(n) is then used to find an encryption exponent e that is coprime to φ(n). The public key consists of (n, e), while the private key is the decryption exponent d, which is the modular inverse of e (mod φ(n)). The security of RSA relies on the difficulty of factoring large numbers, ensuring that while the public key can encrypt a message, only the private key can decrypt it.
Goldbach’s Conjecture states that every even integer greater than 2 can be expressed as the sum of two primes. To find such a pair for a given even integer n, the approach is typically to iterate through potential primes less than n, and check if the difference between n and this prime is also a prime. While straightforward in description, there is no known algorithm that avoids testing all pairs effectively, due to the conjecture's unproven nature in the general case.