Elgamal Based DSA
Elgamal Based DSA
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
bool isPrime(int n) {
if (n % 2 == 0 || n % 3 == 0) return false;
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
int result = 1;
a = a % m;
while (b > 0) {
if (b % 2 == 1)
result = (result * a) % m;
b = b / 2;
a = (a * a) % m;
return result;
}
int num;
do {
} while (!isPrime(num));
return num;
p = generatePrime(100, 1000);
g = rand() % (p - 1) + 1;
x = rand() % (p - 1) + 1;
y = modExp(g, x, p);
void encrypt(int p, int g, int y, int plaintext, int &c1, int &c2) {
int k = rand() % (p - 1) + 1;
c1 = modExp(g, k, p);
return plaintext;
int main() {
srand(time(0));
int p, g, x, y;
generateKeys(p, g, x, y);
cout << "Public Key (p, g, y): (" << p << ", " << g << ", " << y << ")" << endl;
cout << "Encrypted Message (c1, c2): (" << c1 << ", " << c2 << ")" << endl;
return 0;
#include <cmath>
#include <string>
bool isPrime(int n) {
if (n % 2 == 0 || n % 3 == 0) return false;
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
if (b == 0)
return a;
else
if (!isPrime(p) || !isPrime(q)) {
return;
n = p * q;
if (gcd(e, phi) == 1)
break;
if ((d * e) % phi == 1)
break;
return decryptedMsg;
}
int main() {
int p, q, n, e, d;
generateKeys(p, q, n, e, d);
cout << "Public Key (n, e): (" << n << ", " << e << ")" << endl;
cout << "Private Key (n, d): (" << n << ", " << d << ")" << endl;
int msg;
return 0;
SHA-
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
};
// Function to perform SHA-512 padding
string padding;
return padding;
uint64_t w[80];
uint64_t a, b, c, d, e, f, g, h;
uint64_t H[8] = {
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL,
0xa54ff53a5f1d36f1ULL,
};
// Message schedule
// Extend the first 16 words into the remaining 64 words w[16..63] of the message schedule array
s2 = w[i - 2] >> 6;
}
// Initialize working variables to current hash value
a = H[0];
b = H[1];
c = H[2];
d = H[3];
e = H[4];
f = H[5];
g = H[6];
h = H[7];
temp2 = S0 + maj;
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
H[0] += a;
H[1] += b;
H[2] += c;
H[3] += d;
H[4] += e;
H[5] += f;
H[6] += g;
H[7] += h;
stringstream ss;
return ss.str();
string hash;
return hash;
int main() {
string message;
getline(cin, message);
return 0;
return R;
}
int main() {
// Choose a base point on the curve (for demonstration purposes)
Point base = { 5, 1 };
// Choose a scalar (private key)
int scalar = 3;
cout << "Base Point: (" << base.x << ", " << base.y << ")" << endl;
cout << "Scalar: " << scalar << endl;
cout << "Public Key: (" << publicKey.x << ", " << publicKey.y << ")"
<< endl;
return 0;
}