![]() |
VOOZH | about |
In cryptography, the two commonly used algorithms in modern cryptography for secure data transmission and to ensure the signatures of digital signatures, are the Rivest-Shamir-Adleman (RSA) algorithm and Digital Signature Algorithm (DSA). We'll learn about RSA and DSA, how they work when are they used, and their differences.
RSA stands for Rivest-Shamir-Adleman. It is a cryptosystem used for secure data transmission. In the RSA algorithm, the encryption key is public but the decryption key is private. This algorithm is based on the mathematical fact that factoring the product of two large prime numbers is not easy. It was developed by Ron Rivest, Adi Shamir, and Leonard Adleman in 1977.
RSA uses modular exponentiation for encryption and decryption. It use two exponents, e and d, where e is public and d is private. Suppose that P is the plaintext and C is the ciphertext. Here are the steps:
Here's an example of how to implement the RSA algorithm in Python:
This code generates RSA keys, encrypts a message using the public key, and decrypts the ciphertext using the private key. The generate_rsa_keys function generates the public and private keys, encrypt function performs encryption, and decrypt function performs decryption.
Output :
Original Message: HELLO
Encrypted Message: [343, 466, 125, 125, 141]
Decrypted Message: HELLO
In this example, the message "HELLO" is encrypted using the RSA algorithm with a randomly generated public key. The encrypted message is represented as a list of numbers. Then, the ciphertext is decrypted using the corresponding private key, resulting in the original message being retrieved successfully.
DSA stand for Digital Signature Algorithm. It is used for digital signature and its verification. It is based on mathematical concept of modular exponentiation and discrete logarithm. It was developed by National Institute of Standards and Technology (NIST) in 1991.
It involves four operations:
w= s-1(mod q) u1=(H(M)*w) (mod q) u2=(r*w) (mod q) v=((gu1*yu2) (mod p)) (mod q)
It v is equal to r, the message that Bob received was signed by Alice and has not been altered otherwise the message has been tampered.
Here's an example of how to implement the DSA (Digital Signature Algorithm) in Python using the 'cryptography' library:
The example showcases the generation of a DSA private key, signing a message using the private key, and verifying the signature using the corresponding public key. Depending on the validity of the signature, it will print either "Signature is valid." or "Signature is invalid."
Output :
Signature is valid.
This output indicates that the signature verification was successful, and the signature is valid for the given message and public key.
RSA | DSA |
|---|---|
It is a cryptosystem algorithm. | It is digital signature algorithm. |
It is used for encryption, digital signature and secure data transmission. | It is used for digital signature and its verification only. |
It uses public key for encryption and private key for decryption and signing. | Whereas, it uses public key for verification and private key for signing. |
It was developed by Ron Rivest, Adi Shamir and Leonard Adleman. | It was developed by National Institute of Standards and Technology (NIST). |
It uses mathematical concept of factorization of product of two large primes. | It uses modular exponentiation and discrete logarithm. |
It is slower in key generation. | While it is faster in key generation as compared to RSA. |
It is faster than DSA in encryption. | While it is slower in encryption. |
It is slower in decryption. | While it is faster in decryption. |
It is best suited for verification and encryption. | It is best suited for signing in and decryption. |
In conclusion, we learn that both algorithms have their unique strengths and weakness. Whereas, RSA is used for secure data transmission and encryption, DSA is used for checking the authenticity of the message, generating and verifying signatures.