|
Get rid of all your templates and namespaces, they serve no purpose.
Use the best guess
|
|
|
|
|
Templates and namespaces are very important for my program.
I have not posted the full code there...
|
|
|
|
|
Manoj7390 wrote: Templates and namespaces are very important for my program. That is most unlikely, and looking at what you have posted you are not using them for any good reason. You should get the code working first without the use of either, and then add them (if they are really necessary) at a later stage.
Use the best guess
|
|
|
|
|
Starting at the bottom, your main function doesn't make sense - it's one huge syntax error. Even with all the context and the realisation what this is about (encryption), it's almost impossible to guess what it should do.
Obviously you're not familiar with template syntax. Your attempt to invoke a templated function using a templated type is a syntactical mess. Your data structure definitions contain errors related to incomplete or improper template syntax. For that reason, and because you don't really use or need those template parameters, you should really forget about them!
Since you claim you do need the template, use a const instead: in most cases, where people think they need a template, a global/static definition works just as well:
const int P = 263;
Start with your struct definition:
struct encrypt_data_t {
EllipticCurve<P>::Point Pa;
FiniteFieldElement<P> c1;
FiniteFieldElement<P> c2;
};
There: no typedef required, no template parameters required. Also, since the definition is within your namespace, no need to explicitely add the prefix "Cryptography::".
Next, remove any remaining template parameter definition line in your code: if you always used P as the template parameter name, everything should compile after removing the template <argument list> .
Last: fix your main() . I have no idea what your intention is, but you do call a function that returns a struct, and apparently try to assign that struct to an int . That doesn't make sense. Fix it, or at least remove that assignment, so you can find out and fix any remaining syntax errors. Besides, you omitted the return type for main() (always int ), and your main didn't return a value. Both should be listed as errors or at the very least as warnings by your compiler. But it's possible your compiler didn't get that far due to it's inability to resolve previous spaghetti template syntax.
|
|
|
|
|
If I delete template parameter, then it is giving so many errors. I will post the full program to you please fix it.
I want to return {Pa,c1,c2} from this program to another main() function. Please help me out.
#include <cstdlib>
#include <iostream>
#include <vector>
using std:: cout;
using std:: cin;
using std:: endl;
using namespace std;
#include <math.h>
#include "FiniteFieldElement.hpp"
namespace Cryptography
{
template<int P>
class EllipticCurve
{
public:
typedef FiniteFieldElement<P> ffe_t;
class Point
{
friend class EllipticCurve<P>;
typedef FiniteFieldElement<P> ffe_t;
ffe_t x_;
ffe_t y_;
EllipticCurve *ec_;
void addDouble(int m, Point& acc)
{
if ( m > 0 )
{
Point r = acc;
for ( int n=0; n < m; ++n )
{
r += r;
}
acc = r;
}
}
Point scalarMultiply(int k, const Point& a)
{
Point acc = a;
Point res = Point(0,0,*ec_);
int i = 0, j = 0;
int b = k;
while( b )
{
if ( b & 1 )
{
addDouble(i-j,acc);
res += acc;
j = i;
}
b >>= 1;
++i;
}
return res;
}
void add(ffe_t x1, ffe_t y1, ffe_t x2, ffe_t y2, ffe_t & xR, ffe_t & yR) const
{
if ( x1 == 0 && y1 == 0 )
{
xR = x2;
yR = y2;
return;
}
if ( x2 == 0 && y2 == 0 )
{
xR = x1;
yR = y1;
return;
}
if ( y1 == -y2 )
{
xR = yR = 0;
return;
}
ffe_t s;
if ( x1 == x2 && y1 == y2 )
{
s = (3*(x1.i()*x1.i()) + ec_->a()) / (2*y1);
xR = ((s*s) - 2*x1);
}
else
{
s = (y1 - y2) / (x1 - x2);
xR = ((s*s) - x1 - x2);
}
if ( s != 0 )
{
yR = (-y1 + s*(x1 - xR));
}
else
{
xR = yR = 0;
}
}
Point(int x, int y)
: x_(x),
y_(y),
ec_(0)
{}
Point(int x, int y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
Point(const ffe_t& x, const ffe_t& y, EllipticCurve<P> & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
public:
static Point ONE;
Point(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
}
Point& operator=(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
return *this;
}
ffe_t x() const { return x_; }
ffe_t y() const { return y_; }
unsigned int Order(unsigned int maxPeriod = ~0) const
{
Point r = *this;
unsigned int n = 0;
while( r.x_ != 0 && r.y_ != 0 )
{
++n;
r += *this;
if ( n > maxPeriod ) break;
}
return n;
}
Point operator-()
{
return Point(x_,-y_);
}
friend bool operator==(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ == rhs.ec_) && (lhs.x_ == rhs.x_) && (lhs.y_ == rhs.y_);
}
friend bool operator!=(const Point& lhs, const Point& rhs)
{
return (lhs.ec_ != rhs.ec_) || (lhs.x_ != rhs.x_) || (lhs.y_ != rhs.y_);
}
friend Point operator+(const Point& lhs, const Point& rhs)
{
ffe_t xR, yR;
lhs.add(lhs.x_,lhs.y_,rhs.x_,rhs.y_,xR,yR);
return Point(xR,yR,*lhs.ec_);
}
friend Point operator*(int k, const Point& rhs)
{
return Point(rhs).operator*=(k);
}
Point& operator+=(const Point& rhs)
{
add(x_,y_,rhs.x_,rhs.y_,x_,y_);
return *this;
}
Point& operator*=(int k)
{
return (*this = scalarMultiply(k,*this));
}
friend ostream& operator <<(ostream& os, const Point& p)
{
return (os << "(" << p.x_ << ", " << p.y_ << ")");
}
};
typedef EllipticCurve<P> this_t;
typedef class EllipticCurve<P>::Point point_t;
EllipticCurve(int a, int b)
: a_(a),
b_(b),
m_table_(),
table_filled_(false)
{
}
void CalculatePoints()
{
int x_val[P];
int y_val[P];
for ( int n = 0; n < P; ++n )
{
int nsq = n*n;
x_val[n] = ((n*nsq) + a_.i() * n + b_.i()) % P;
y_val[n] = nsq % P;
}
for ( int n = 0; n < P; ++n )
{
for ( int m = 0; m < P; ++m )
{
if ( x_val[n] == y_val[m] )
{
m_table_.push_back(Point(n,m,*this));
}
}
}
table_filled_ = true;
}
Point operator[](int n)
{
if ( !table_filled_ )
{
CalculatePoints();
}
return m_table_[n];
}
size_t Size() const { return m_table_.size(); }
int Degree() const { return P; }
FiniteFieldElement<P> a() const { return a_; }
FiniteFieldElement<P> b() const { return b_; }
template<int T>
friend ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve);
ostream& PrintTable(ostream &os, int columns=4);
private:
typedef std::vector<Point> m_table_t;
m_table_t m_table_;
FiniteFieldElement<P> a_;
FiniteFieldElement<P> b_;
bool table_filled_;
};
template<int T>
typename EllipticCurve<T>::Point EllipticCurve<T>::Point::ONE(0,0);
template<int T>
ostream& operator <<(ostream& os, const EllipticCurve<T>& EllipticCurve)
{
os << "y^2 mod " << T << " = (x^3" << showpos;
if ( EllipticCurve.a_ != 0 )
{
os << EllipticCurve.a_ << "x";
}
if ( EllipticCurve.b_.i() != 0 )
{
os << EllipticCurve.b_;
}
os << noshowpos << ") mod " << T;
return os;
}
template<int P>
ostream& EllipticCurve<P>::PrintTable(ostream &os, int columns)
{
if ( table_filled_ )
{
int col = 0;
typename EllipticCurve<P>::m_table_t::iterator iter = m_table_.begin();
for ( ; iter!=m_table_.end(); ++iter )
{
os << "(" << (*iter).x_.i() << ", " << (*iter).y_.i() << ") ";
if ( ++col > columns )
{
os << "\n";
col = 0;
}
}
}
else
{
os << "EllipticCurve, F_" << P;
}
return os;
}
}
namespace utils
{
float frand()
{
static float norm = 1.0f / (float)RAND_MAX;
return (float)rand()*norm;
}
int irand(int min, int max)
{
return min+(int)(frand()*(float)(max-min));
}
}
using namespace Cryptography;
using namespace utils;
int main(int argc, char *argv[])
{
typedef EllipticCurve<263> ec_t;
ec_t myEllipticCurve(1,1);
cout << "A little Elliptic Curve cryptography example\nby Jarl Ostensen, 2007\n\n";
cout << "The elliptic curve: " << myEllipticCurve << "\n";
myEllipticCurve.CalculatePoints();
cout << "\nPoints on the curve (i.e. the group elements):\n";
myEllipticCurve.PrintTable(cout,5);
cout << "\n\n";
ec_t::Point P = myEllipticCurve[2];
cout << "some point P = " << P << ", 2P = " << (P+P) << "\n";
ec_t::Point Q = myEllipticCurve[3];
cout << "some point Q = " << Q << ", P+Q = " << (P+Q) << "\n";
ec_t::Point R = P;
R += Q;
cout << "P += Q = " << R << "\n";
R = P;
R += R;
cout << "P += P = 2P = " << R << "\n";
cout << "\nEC message encryption example\n===============================================\n\n";
ec_t::Point G = myEllipticCurve[0];
while( (G.y() == 0 || G.x() == 0) || (G.Order()<2) )
{
int n = (int)(frand()*myEllipticCurve.Size());
G = myEllipticCurve[n];
}
cout << "G = " << G << ", order(G) is " << G.Order() << "\n";
int a = irand(1,myEllipticCurve.Degree()-1);
ec_t::Point Pa = a*G;
cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;
int b = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pb = b*G;
cout << "Bob's public key Pb = " << b << "*" << G << " = " << Pb << endl;
int j = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pj = j*G;
cout << "Jane's public key Pj = " << j << "*" << G << " = " << Pj << endl;
cout << "\n\n";
int m1,m2;
cout << "Enter two message\n"<< endl;
cin >> m1;
cin >> m2;
cout << "Plain text message from Alice to Bob: (" << m1 << ", " << m2 << ")\n";
ec_t::Point Pk = a*Pb;
ec_t::ffe_t c1( m1*Pk.x() );
ec_t::ffe_t c2( m2*Pk.y() );
cout << "Encrypted message from Alice to Bob = {Pa,c1,c2} = {" << Pa << ", " << c1 << ", " << c2 << "}\n\n";
Pk = b*Pa;
ec_t::ffe_t m1d = c1/Pk.x();
ec_t::ffe_t m2d = c2/Pk.y();
cout << "\tBob's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
Pk = j*Pa;
m1d = c1/Pk.x();
m2d = c2/Pk.y();
cout << "\nJane's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
cout << endl;
}
|
|
|
|
|
Without the declaration of the class FiniteFieldElement, and without the error messages, I can't help you. I've successfully compiled that code by using the following dummy declaration:
template <int P>
class FiniteFieldElement {
public:
FiniteFieldElement(){}
FiniteFieldElement(int){}
int i() const {return 0;}
operator int() const {return 0;}
};
This means that either there is a problem with the actual class declaration, or you are not using it correctly.
|
|
|
|
|
The code is working fine. I need to return those three variables i.e. {Pa,c1,c2} from that program to another main program. What should i have to do. I have used structure for that but its not working. Please tell how to return a three user defined data type to the main function
|
|
|
|
|
Manoj7390 wrote: The code is working fine.
Now, that is news!
From your original posting:
Manoj7390 wrote: <layer>I am getting so many errors
May be you should have been clearer from the start about this...
|
|
|
|
|
There can only be one int main() . You have to separate the code that does the calculations from the code that inquires the input. You have plenty of functions that pass values around, so I don't see why there should be a problem passing these values via a function interface.
|
|
|
|
|
how to return those values using structure or by declaring class
|
|
|
|
|
Change the struct definition to
template<int P> struct encrypt_data_t {
typename Cryptography::EllipticCurve<P>::Point Pa;
FiniteFieldElement<P> c1;
FiniteFieldElement<P> c2;
} ;
Then call this function like this:
int main(...) {
const int MY_P = 263;
...
encrypt_data_t<MY_P> result = my_encrypt<MY_P>();
...
}
Of course, you also have to fix your function code - the code you posted does not declare half the variables it uses.
Or you could just skip that structure and instead pass these values back by reference[^]:
template <int P>
void my_encrypt(typename Cryptography::EllipticCurve<P>::Point& Pa,
FiniteFieldElement<P>& c1, FiniteFieldElement<P>& c2) {
...
}
int main(...) {
const int MY_P = 263;
typename Cryptography::EllipticCurve<MY_P>::Point Pa;
FiniteFieldElement<MY_P> c1;
FiniteFieldElement<MY_P> c2;
my_encrypt(Pa, c1, c2);
}
|
|
|
|
|
I need to develop a tool which peroform all operation on USB drive attached on other computer.
Application needs to perform all operation which can be perform by local compter.
Please guide me how to start and wnat things I need to lookinto?
|
|
|
|
|
Could you clarify which operation you have to perform?
What is USB drive on other computer/local computer?
|
|
|
|
|
|
Once a USB drive is attached to another computer, the drivers will install on the other computer as well.
On this being done and said, you can then access the contents of the USB drive just like any other remote drive.
Not sure what do you mean by "all operation". the above is answered assuming you are querying for copy/paste and other basic functionalities.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
Hi
I am getting the following compiler error in that the compiler can't find filea.cpp
I am using visual studio 2010 professional
The file appear in my project -> source files
When I right click in each of the .cpp source files and compile them Separately they each compile
cleanly including filea.cpp
Is there anyway to tell where this compiler error is coming from
Thanks
|
|
|
|
|
Why is it referring to the file with two elipses (i.e., parent folder) notation?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Don't know here is the actual build output
1>------ Rebuild All started: Project: TunTap32, Configuration: Release x64 ------
1>Build started 6/19/2013 11:45:32 AM.
1>_PrepareForClean:
1> Deleting file "x64\Release\TunTap32.lastbuildstate".
1>InitializeBuildStatus:
1> Touching "x64\Release\TunTap32.unsuccessfulbuild".
1>ClCompile:
1> StdAfx.cpp
1> fishtrace.cpp
1> TT32api.cpp
1> TTAdapter.cpp
1> TunTap.cpp
1> TunTap32.cpp
1> fishtrace.cpp
1>c1xx : fatal error C1083: Cannot open source file: '..\fishtrace.cpp': No such file or directory
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.20
|
|
|
|
|
Try removing (but not deleting) the file from your project, and then adding it back in. You should familiarise yourself with rules of projects as this sort of issue can crop up unexpectedly. Open the project file in Notepad (but be careful not to corrupt it) and see how the rules are put together.
Use the best guess
|
|
|
|
|
Look in the project's VCPROJ file for a reference to each of these files. See if you notice anything different about fishtrace.cpp .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi,
I am using DirectShow to Play / Pause / Stop and Capture Video files. But Capturing and playing of video files is simple. I want to Implement HD Video recording in my project.
Anybody have any idea of how to Implement HD Video Capturing using DirectShow.?
Or Apart from DirectShow, is there any other method to Implement HD Video recording in MFC.
Regards,
Mbatra
|
|
|
|
|
Hi,I need to open a httpfile by Proxy Server,but the UserName and Password I set always fail,I don't know why,I tried many times,I don't know how to do,Can you have any ideas.
Here is My code:
CString strURL = _T("http://www.kkkk.com/");
CInternetSession Session(_T("Get Xml"));
CHttpFile *lpFile = NULL;
try
{
//set proxy info
char sProxyList[MAX_PATH], sProxyName[64],sProxyPassw[64];
strcpy(sProxyName,"mmm");
strcpy(sProxyPassw,"mmm");
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy =_T("192.168.0.1:8080");
proxyinfo.lpszProxyBypass = NULL;
Session.SetOption(INTERNET_OPTION_PROXY,(LPVOID)&proxyinfo,sizeof(INTERNET_PROXY_INFO));//Success
if (! Session.SetOption(INTERNET_OPTION_PROXY_USERNAME, sProxyName, strlen(sProxyName)+1))
{
DWORD ret = GetLastError();//Always return 12018.Why?
}
if (! Session.SetOption(INTERNET_OPTION_PROXY_PASSWORD, sProxyPassw, strlen(sProxyPassw)+1))
{
DWORD ret = GetLastError(); //Always return 12018.Why?
}
}
lpFile = (CHttpFile*)Session.OpenURL(strURL,1,INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE);
if (lpFile != NULL)
{
while(TRUE)
{
char szBuff[1024] = {0};
if ( lpFile->Read(szBuff, 1024) <= 0)
{
break;
}
strContent += szBuff;
}
}
}catch(CInternetException* pEx)
{
TCHAR pszError[64];
pEx->GetErrorMessage(pszError, 64);
strErrorMsg = pszError;
pEx->Delete();
}
delete lpFile;
lpFile = NULL;
Session.Close();
|
|
|
|
|
Error code 12018 is described here[^].
Use the best guess
|
|
|
|
|
Hello, i have a question about the MSXML library. I fail to find how exactly they read the XML Document when its already loaded into memory. If i look for XML nodes do they read the whole document from top to bottom until find it or its something with hash tables.
My problem is that i have to remove some elements for existent XML document and add it in another. I was wondering which is better(according to speed) to keep the XML Nodes in std::vectors and remove the needed items and put them in the new XML Document and this only with 2 read/write operations on the XML Document or i should get the first part of the items do whatever i have to do with them and then take the next part and so on. This will cause for at least 8 times reading the existent XML Document and getting XML NodeLists out of it. The problem here is that the first XML Document can be really big.
I think its better to read the information only once and do what i have to do with it and then write it in the new XML Document. At least i think its gonna be faster but i am not sure exactly how MSXML does the operations on the XML Document.
Thank you for your help.
|
|
|
|
|
Argonia wrote: I fail to find how exactly they read the XML Document when its already loaded into memory. Did you look at the selectSingleNode() method?
Argonia wrote: My problem is that i have to remove some elements for existent XML document and add it in another. So why not let MSXML do this for you? For a given node (see IXMLDOMNode), use the removeChild() method.
Argonia wrote: ...but i am not sure exactly how MSXML does the operations on the XML Document. While there are certainly better and more exhaustive examples available, I show how to briefly use MSXML here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|