0% found this document useful (0 votes)
10 views3 pages

Chipper by RSA Crypto

The document contains a C++ implementation of the RSA encryption algorithm, including functions for calculating GCD, modular exponentiation, and modular inverse. It also includes key generation, encryption, and decryption processes, with a sample message demonstrating the functionality. The code has some syntax errors and inconsistencies that need to be corrected for proper execution.

Uploaded by

Hey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Chipper by RSA Crypto

The document contains a C++ implementation of the RSA encryption algorithm, including functions for calculating GCD, modular exponentiation, and modular inverse. It also includes key generation, encryption, and decryption processes, with a sample message demonstrating the functionality. The code has some syntax errors and inconsistencies that need to be corrected for proper execution.

Uploaded by

Hey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <bits/stdc++.

h>

Using namespace std;

// Function to calculate GCD

Int gcd(int a, int b) {

Return (b == 0) ? a : gcd(b, a % b);

// Function to compute modular exponentiation (a^b % mod)

Long long modExp(long long base, long long exp, long long mod) {

Long long result = 1;

While (exp > 0) {

If (exp % 2 == 1) result = (result * base) % mod;

Base = (base * base) % mod;

Exp /= 2;

Return result;

// Function to compute modular inverse of e under modulo phi

Long long modInverse(long long e, long long phi) {

For (long long d = 1; d < phi; d++)

If ((e * d) % phi == 1)

Return d;

Return -1;

// RSA Key Generation

Void generateKeys(long long &n, long long &e, long long &d) {
Long long p = 61, q = 53; // Choosing two prime numbers

N = p * q; // Compute n

Long long phi = (p – 1) * (q – 1); // Compute Euler’s totient function

E = 17; // Choose e such that 1 < e < phi and gcd(e, phi) = 1

While (gcd(e, phi) != 1) e++;

D = modInverse(e, phi); // Compute private key (d)

// RSA Encryption

Long long encrypt(long long message, long long e, long long n) {

Return modExp(message, e, n);

// RSA Decryption

Long long decrypt(long long cipher, long long d, long long n) {

Return modExp(cipher, d, n);

// Driver Code

Int main() {

Long long n, e, d;

generateKeys(n, e, d);

long long message = 42; // Sample message

cout << “Original Message: “ << message << endl;

long long cipher = encrypt(message, e, n);


cout << “Encrypted Cipher: “ << cipher << endl;

long long decrypted = decrypt(cipher, d, n);

cout << “Decrypted Message: “ << decrypted << endl;

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy