Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ code to encrypt and decrpyt message using technique given below: The RSA Cry

ID: 3863772 • Letter: C

Question

c++ code to encrypt and decrpyt message using technique given below:

The RSA Cryptosystem Beforehand The receiver creates a public key and a secret key as follows.

1. Generate two distinct primes, p and q . Since they can be used to generate the secret key, they must be kept hidden.

2. Let n = pq

3. Select an integer e such that gcd(e,( p -1)(q -1)) =1 . The public key is the pair (e,n) . This should be distributed widely.

4. Compute d such that de congrence()=1(mod (p -1)(q -1)) . This can be done using the Pulverizer. The secret key is the pair (d,n) . This should be kept hidden! Encoding: Given a message m , the sender first checks that gcd(m,n) =1 . The sender then encrypts message m to produce m'using the public key: m'=rem(me ,n) Decoding: The receiver decrypts message m back to message m using the secret key: m rem(m' )d ,n)

Explanation / Answer

#include #include #include #include using namespace std; long int p, q, n, t, flag, e[100], d[100], temp[100], j, m[100], en[100], i; char msg[100]; int prime(long int); void ce(); long int cd(long int); void encrypt(); void decrypt(); int prime(long int pr) { int i; j = sqrt(pr); for (i = 2; i p; flag = prime(p); if (flag == 0) { cout q; flag = prime(q); if (flag == 0 || p == q) { cout msg; for (i = 0; msg[i] != NULL; i++) m[i] = msg[i]; n = p * q; t = (p - 1) * (q - 1); ce(); encrypt(); decrypt(); return 0; } void ce() { int k; k = 0; for (i = 2; i 0) { d[k] = flag; k++; } if (k == 99) break; } } } long int cd(long int x) { long int k = 1; while (1) { k = k + t; if (k % x == 0) return (k / x); } } void encrypt() { long int pt, ct, key = e[0], k, len; i = 0; len = strlen(msg); while (i != len) { pt = m[i]; pt = pt - 96; k = 1; for (j = 0; j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote