4 ms·
Note that this model is not able to write code. Prompt: "Write a C program to RSA encrypt a string." text-embedding-ada-002: %-C C C C C C C C C C C
by tibbar 4y ago
Note that this model is not able to write code.
Prompt: "Write a C program to RSA encrypt a string."
text-embedding-ada-002:
%-C C C C C C C C
C
C
C
C
C C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C C C C C
C C
C C
C
C
C
C
C
C
C
C
C
C
C C C C
C
C
C
C
C C
C
C
C
C
C C
C aC C C
C
m m m m m m m m m m
m m m m m m m m mm m
C mC
(Note: a relatively short max length)
Compare text-davinci-003:
#include <stdio.h>
#include<math.h>
// Utility function to find GCD of 'a'
// and 'b'
int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to find Modular Multiplicative
// Inverse of 'a' under modulo 'm'
int modInverse(int a, int m)
{
a = a % m;
for (int x = 1; x < m; x++)
if ((a * x) % m == 1)
return x;
}
// Function to compute a/b under modulo m
int modDivide(int a, int b, int m)
{
a = a % m;
int inv = modInverse(b, m);
return (inv * a) % m;
}
// Function to calculate (a^b)%c
long long int power(int a, int b, int c)
{
int res = 1;
a = a % c;
while (b > 0)
{
if (b & 1)
res = modDivide(res * a, 1, c);
b = b >> 1;
a = modDivide(a * a, 1, c);
}
return res;
}
// C function for extended Euclidean Algorithm
int gcdExtended(int a, int b, int x, int y)
{
if (a == 0)
{
x = 0;
y = 1;
return b;
}
int x1, y1;
int gcd = gcdExtended(b%a, a, &x1, &y1);
x = y1 - (b/a) x1;
y = x1;
return gcd;
}
// Function to generate public and private
// keys
void generateKeys(int p, int q, int e,
int d, int n)
{
// n = pq
n = p * q;
// Computing phi(n) = (p-1)*(q-1)
int phi = (p - 1) * (q - 1);
// Choose an integer e such that
// e and phi(n) are co-prime
*e = 2;
while (*e < phi)
{
if (gcd(*e, phi)==1)
break;
else
++*e;
}
// Compute d such that it satisfies
// d*e = 1 + k * phi(n)
int k = 2; // Fixed value
*d = (1 + (k * phi))/ *e;
}
// Encryption Function
long int RSA_Encrypt(int msg, int e, int n)
{
// Cipher Text c = (msg ^ e) % n
long int c = power(msg, e, n);
return c;
}
// Decryption Function
long int RSA_Decrypt(int c, int d, int n)
{
// Message msg = (c ^ d) % n
long int msg = power(c, d, n);
return msg;
}
// Driver program
int main()
{
// Two random prime numbers
int p = 3;
int q = 7;
// Message to be encrypted
int msg = 15;
// Encryption key (e, n)
int e, d, n;
// Calculate n and phi
generateKeys(p, q, &e, &d, &n);
// Encryption
long int c = RSA_Encrypt(msg, e, n);
printf("Encrypted message is: %d\n", c);
// Decryption
long int m = RSA_Decrypt(c, d, n);
printf("Original Message is: %d\n", m);
return 0;
}
- varunkmohan 4y agoIt's an embedding model so it generates vector embeddings not text generations. That's to be expected.