Here is the code below. The code is about RSA.
#include "rsa.h"
int main()
{
RSA rsa(13, 77);
rsa.crypt("plainFile", "cipherFile");
return 0;
}
rsa.cpp
<pre>#include "rsa.h"
#include <fstream>
#include <cmath>
RSA :: RSA(int k, int m)
: key(k), modulus(m)
{
}
RSA :: ~RSA()
{
}
void RSA :: crypt(const char* inFile, const char* outFile)
{
ifstream istrm(inFile, ios :: in);
ofstream ostrm(outFile, ios :: out);
int base, result;
while (istrm >> base)
{
result = modulo(base, key, modulus);
ostrm << result;
ostrm << ' ';
}
istrm.close();
ostrm.close();
}
int RSA:: modulo(int base, int power, int modulus)
{
int result = 1;
for (int i = 0; i < power; i++)
{
result = (result * base) % modulus;
}
return result;
}
rsa.h
<pre>#ifndef RSA_H
#define RSA_H
#include <iostream>
using namespace std;
class RSA
{
private:
int key;
int modulus;
int modulo(int base, int power, int modulus);
public:
RSA(int key, int modulus);
~RSA();
void crypt(const char* inFile, const char* outFile);
};
#endif
The output should be
Contents of Plaintext File:
14 27 12 45 9 64 22 8
Contents of Ciphertext File:
49 48 12 45 58 36 22 50
Now I would like to make this output become input, and get this output
#include "rsa.h"
int main ()
{
RSA rsa (13, 77); rsa.crypt ("plainFile", "cipherFile"); return 0;
}
I try to exchange input and output but don't know where to start, can I just change a little bit to do that? or I need to rewrite the code? anyone can help? How should I do it? Thanks.
What I have tried:
I try to use a vector for current output but don't know how to do that.