Question

In: Computer Science

Write C program for RSA encryption and decryptin, where: p = 11,q = 5, e =...

Write C program for RSA encryption and decryptin, where: p = 11,q = 5, e = 7

Solutions

Expert Solution

#include<stdio.h>
#include<math.h>

// To find gcd
int gcd(int a, int h)
{
    int temp;
    while(1)
    {
        temp = a%h;
        if(temp==0)
        return h;
        a = h;
        h = temp;
    }
}

int main()
{
    //Two random prime numbers
    double p = 11;
    double q = 5;
    double n=p*q;
    double count;
    double totient = (p-1)*(q-1);

    //public key
    //e stands for Encrypt
    double e=7;

    //for checking co-prime which satisfies e>1


    while(e<totient){
    count = gcd(e,totient);
    if(count==1)
        break;
    else
        e++;
    }

    //private key
    //d stands for decrypt
    double d;

    //k can be any arbitrary value
    double k = 2;

    //choosing d such that it satisfies d*e = 1 + k * totient
    d = (1 + (k*totient))/e;
    double msg = 12;
    double c = pow(msg,e);
    double m = pow(c,d);
    c=fmod(c,n);
    m=fmod(m,n);

    printf("Message data = %lf",msg);
    printf("\np = %lf",p);
    printf("\nq = %lf",q);
    printf("\nn = pq = %lf",n);
    printf("\ntotient = %lf",totient);
    printf("\ne = %lf",e);
    printf("\nd = %lf",d);
    printf("\nEncrypted data = %lf",c);
    printf("\nOriginal Message Sent = %lf",m);

    return 0;
}


Related Solutions

Given the prime factors p and​ q, the encryption exponent​ e, and the ciphertext​ C, apply...
Given the prime factors p and​ q, the encryption exponent​ e, and the ciphertext​ C, apply the RSA algorithm to find ​(a) the decryption exponent d and ​(b) the plaintext message M. p q e C 17 5 19 65 I have to get d and M
Write a Java program for RSA encryption that has the following inputs and outputs: Given a...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).
QUESTION 26 Consider RSA with p = 7 and q = 11. What are n and...
QUESTION 26 Consider RSA with p = 7 and q = 11. What are n and z? n z 4 points    QUESTION 27 Put the following wireless encryption protocols in order from most secure to least secure.       -       1.       2.       3.          WPA       -       1.       2.       3.          WEP       -       1.       2.   ...
Computer Security Sara is using RSA crypto-system with the following setup: p = 11 and q...
Computer Security Sara is using RSA crypto-system with the following setup: p = 11 and q = 3. Sara publish his Public Key: (n, e) = (33, 3). a. Find n, Ф(n). b. Calculate Sara’s private key. c. Nora wants to send the message M = 13 to Sara. Using Sara’s public and private keys, calculate the ciphertext C, and the value for Message R, when Sara recovers the message. d. Deem wants to set up his own public and...
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) If you...
Write a C++ program to construct the truth table of P ∨¬(Q ∧ R) If you could include comments to explain the code that would be much appreciated!!! :) Thank you so much!
write a program that will print a truth table for p ^ ~q. Using C++ please.
write a program that will print a truth table for p ^ ~q. Using C++ please.
import math print("RSA ENCRYPTION/DECRYPTION") print("*****************************************************") #Input Prime Numbers print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:")...
import math print("RSA ENCRYPTION/DECRYPTION") print("*****************************************************") #Input Prime Numbers print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:") p = int(input("Enter a prime number for p: ")) q = int(input("Enter a prime number for q: ")) print("*****************************************************") #Check if Input's are Prime '''THIS FUNCTION AND THE CODE IMMEDIATELY BELOW THE FUNCTION CHECKS WHETHER THE INPUTS ARE PRIME OR NOT.''' def prime_check(a): if(a==2): return True elif((a<2) or ((a%2)==0)): return False elif(a>2): for i in range(2,a): if not(a%i): return false return True check_p =...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
8. (20 pts) a. RSA encryption. Let n = pq = (7)(17) = 119 and e...
8. (20 pts) a. RSA encryption. Let n = pq = (7)(17) = 119 and e = 5 define a (very modest) RSA public key encryption. Since 25 < 119 < 2525, we can only encode one letter (two digit representation) at a time. Use the function ? = ? mod ? to encode the word MATHY into a series of five numbers that are less than n. b. To decrypt an RSA encrypted message, we need to find d,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT