ok.. its really hard and takes time and knowlage of C++..
i hope i am in the right section for this.. if no please the mods move it to the right one..
Whoever manage to make over it... is god for me. i can give one premium rs account valid til 23 Octomber 2010 if anyone can make this.. please let me send the rs account only when the compiler runs it..
Its a program i need make at C - C++. it need make RSA algorithm with the following. all you have to do is complete where its empty with the codes of Encryption, Decription and Constraction of keys where it say "==== PUT YOUR FUNCTIONS HERE ====".
For any questions ask me here..
here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define MAX_BITS 64 /* Max integer that will have 2^64 - 1 bits */
#define MAX_CHARS 100 /* Max character's number that get readed by fgets() */
#define LENGTH_P 9 /* Lenght of p in decimals */
#define LENGTH_Q 9 /* Lenght of q in decimals */
#define BLOCK_SIZE 8 /* will be cryptographed 8 ASCII characters by section */
/* For the constract of keys */
void NewSeed (void);
long long ModMult(long long a, long long b, long long mod);
int RabinMiller(long long candidate);
long long ModInverse(long long val, long long mod);
/* For the cryptography */
void GetBlock(char *block, FILE *fp, int numChars);
int main(int argc, char **argv){
}
/* ==== PUT YOUR FUNCTIONS HERE ====*/
/* *********************************************************************** */
/* *********************************************************************** */
void NewSeed (void){
srand( (unsigned) time( NULL )); /* Seed = current time. */
}
/* *********************************************************************** */
long long ModMult(long long a, long long b, long long mod){
/* Perform res = (a * b) % mod, avoiding intermediate overflow */
long long res = 0;
long long a1 = a % mod;
long long b1 = b % mod;
while(b1 != 0){
if(b1 & 1)
res = (res + a1) % mod;
a1 = (a1 << 1) % mod;
b1 >>= 1;
}
return res;
}
/* *********************************************************************** */
/* Requires stdlib.h */
int RabinMiller(long long candidate){
long long a, n, d, x, t, rem;
int i, j;
/* const int MaxBits = 64; */ /* Allow for a max int of 2^64 - 1 */
int bits[MAX_BITS];
int roundFailed = 1; /* Boolean */
n = candidate;
t = n - 1;
for(i=0; i<MAX_BITS; i++){
rem = t % 2;
if(rem == 1)
bits[i] = 1;
else
bits[i] = 0;
if(t == 0)
break;
t /= 2;
}
/* Main algorithm starts here */
for(j=0; j<5; j++){ /* Perform 5 rounds against 5 random bases */
a = (2 + (long long) rand()) % (n-1); /* Ensure 1 < a < n-1
-- rand() produces smaller than n-1 for large n */
d = 1;
x = 0;
for(; i>=0; i--){
x = d;
d = ModMult(d, d, n);
if(d == 1 && x != 1 && x != n - 1)
roundFailed = 1;
if(bits[i])
d = ModMult(d, a, n);
}
if(d != 1)
roundFailed = 1;
else
roundFailed = 0;
if(roundFailed)
return 0;
}
/* If this point has been reached, then the candidate number has passed
all rounds successfully. */
return 1;
}
/* *********************************************************************** */
long long ModInverse(long long val, long long mod){
long long c1, c2, c3, t, b1, b2, b3;
int sign = 0;
c1 = mod;
c2 = val;
c3 = 0;
b1 = 0;
b2 = 1;
b3 = 0;
t = 0;
do{
t = c1 / c2;
c3 = c1 % c2;
b3 = t * b2;
b3 = b1 + b3;
c1 = c2;
c2 = c3;
b1 = b2;
b2 = b3;
sign++;
}while(c2 != 0);
if(sign % 2 == 0)
b1 = mod - b1;
return b1;
}
/* *********************************************************************** */
/*
Reads numChars from file pointer fp and stores them to block.
if there are less than numChars characters, pad out with spaces
*/
void GetBlock(char *block, FILE *fp, int numChars){
int i = 0, charsRead = 0;
char c, str[BLOCK_SIZE+1];
while((c = fgetc(fp)) != EOF && i < numChars){
if(c == '\n')
continue;
str[i] = c;
i++;
}
charsRead = i;
if(c != EOF) /* There are more chars in the file, but the block is full */
ungetc(c, fp);
if(charsRead < numChars){ /* Need to pad out with blanks */
for(i=charsRead; i <= numChars; i++)
str[i] = ' ';
}
str[numChars] = '\0'; /* Add string terminator */
strcpy(block, str);
}
/* *********************************************************************** */