Permalink
Browse files

elgamal shit

  • Loading branch information...
Simon Lüke
Simon Lüke committed Jan 13, 2018
1 parent 38c3f5f commit f0c3daffdbe5ec6174ab3b5a241618c0df942c93
@@ -19,9 +19,11 @@ static unsigned short openkey = 32;
static unsigned short openkey_sender = 16;
static unsigned char decrypt(char *c)
static unsigned char decrypt(unsigned char *c)
{
return 97;
unsigned long b = mod_exp(openkey_sender, secret * (order - 2) , order);
unsigned long m = mod_exp(b * (unsigned short) c, 1, order);
return (unsigned char) m;
}
static int elgamal_open(struct inode *inode, struct file *file)
@@ -5,12 +5,54 @@
#include <stdio.h>
#include <unistd.h>
// start
#include "mod_exp.h"
static unsigned short order = 59;
static unsigned short generator = 2;
static unsigned short secret = 5;
static unsigned short openkey = 32;
static unsigned short openkey_sender = 16;
static unsigned char decrypt(unsigned char *c)
{
unsigned long b = mod_exp(openkey_sender, secret * (order - 2) , order);
unsigned long m = mod_exp(b * (unsigned short) c, 1, order);
return (unsigned char) m;
}
static unsigned char encrypt(unsigned char *m)
{
unsigned long i, tmp = openkey;
for(i = 1; i < 4; i++)
{
tmp *= openkey;
}
tmp = tmp * (unsigned long) m % order;
return (unsigned char) tmp;
}
//end
int main(int argc, char** argv)
{
unsigned char x = 120;
int fd = open("/dev/brpa3_968757_953527", O_RDWR);
write(fd, 121, 1);
read(fd, &x, 1);
printf("Read: %c\n", x);
//start
int i;
for(i = 1; i <= 58; i++)
{
printf("Plain: %d, ", i);
x = encrypt(i);
printf("Encrypted: %d, ", x);
x = decrypt(i);
printf("Decrypted: %d\n", x);
}
//end
return 0;
}
@@ -26,7 +26,6 @@ unsigned long mod_exp(unsigned short base, unsigned short exp, unsigned short mo
}
for(e2 = 1; e2 <= exp; e2++)
{
unsigned tmp = c;
c = (c * base) % mod;
}
return c;

0 comments on commit f0c3daf

Please sign in to comment.