|
Nope. However, the DLL project contains just two important files, namely resample.c and resample.h . You may generate a DLL project skeleton via Visual Studio 6 Application Wizard and then add such files to it (probably you have to replace the generated header and source).
It should be simple.
You may even embed the resample.c and resample.h content directly into your project (that is without the need of loading the DLL ).
Veni, vidi, vici.
|
|
|
|
|
It looks like someone has given you a solution, so I'll explain a bit why this happens.
The resizing of your image using GDI is a simple re-sampling algorithm. When you shrink it, pixels in a horizontal and vertical direction are removed, at a semi regular spacing, to make the image fit the new size.
This has the effect of producing a horizontal and vertical waveform in your image.
Your parallel lines in the image, also make up a wave pattern.
When these two wave patterns interact, you get an interference pattern and see the Moire' effect.
http://en.wikipedia.org/wiki/Moire_effect[^]
|
|
|
|
|
Hi all,
I'm about to embark on my first development project. I'm really happy to see so much community spirit and collaboration going on online. Im going to be using the Neurosky SDK with C++ in order to read brainwave data, and I'll be using that data to manipulate the responsiveness of an Xbox 360 controller depending on how well the user is concentrating. Hopefully it'll be a fun little tool to assist gamers in staying alert!
If anyone has experience with XINPUT and has some pointers to set me off in the right direction that would be great!
I do have a specific question too. - How best to approach the issue of Computer Games reading directly from the Xbox controller and ignoring my program altogether?
All suggestions welcome!
|
|
|
|
|
This is really not a C++ question, and I suspect you would get better support by looking at some of these links[^].
Use the best guess
|
|
|
|
|
Kindly send or inform me if you can help me out.
Thanks
|
|
|
|
|
Please do not cross post. Pick one forum and stick to it.
|
|
|
|
|
Trying to build my own source filter (AVI format) I always get connection error with AVI Splitter.
Please take in mind that I am trying to open a fully functional avi video file, that works just fine with microsoft's async file and I that tried at the very begginng to change my mediatype declaration without success.
The error description in the graphEdit is "These filters cannot agree on connection. Verify type compatibility of input pin and output pin. Return code VFW_E_INVALID_FILE_FORMAT
0x8004022F".
DXerr.exe reports :
HRESULT: 0x80040207 (2147746311)
Name: DIERR_NOTBUFFERED
VFW_E_NO_ACCEPTABLE_TYPES
Description: Attempted to read buffered device data from a device that is not buffered. & There is no common media type between these pins.
Severity code: Failed
Facility Code: FACILITY_ITF (4)
Error Code: 0x0207 (519)
My mediatype is declared as :
const AMOVIESETUP_MEDIATYPE sudOpPinTypes =
{
&MEDIATYPE_Stream,
&MEDIASUBTYPE_NULL
};
I debugged the code and I found that somewhere in the
HRESULT CBasePin::AgreeMediaType(IPin *pReceivePin, const CMediaType *pmt) inside the amfilter.cpp is gettings first the AVI Splitter's MediaType list with the folowing code :
hr = pReceivePin->EnumMediaTypes(&pEnumMediaTypes);
Ok with that. Then it tries all mediatypes inside the method
HRESULT CBasePin::TryMediaTypes(IPin *pReceivePin, __in_opt const CMediaType *pmt, IEnumMediaTypes *pEnum)
by retriving them one by one with the following statement
hr = pEnum->Next(1, (AM_MEDIA_TYPE**)&pMediaType,&ulMediaCount);
At this point, the hr result returns S_FALSE and the pMediaType is undefined. The error code is
0x8004022f error code
VFW_E_INVALID_FILE_FORMAT
So the AVISplitter does not purpose any right ?
Now the code beggins to scan my own source filter mediatype list.
Despite the fact that I declared 2 or 3 different mediatypes it returns only one and it fails at
hr = AttemptConnection(pReceivePin, pMediaType); and specifically at
hr = pReceivePin->ReceiveConnection((IPin *)this, pmt);
What am I doing wrong ?
I suspect my MediaType declaration, but i dont see anything wrong. Below I attach the filter's template declarations with only one mediatype.
const WCHAR szAsyncFile[] = L"Async Source (File)";
const WCHAR szAsyncHttp[] = L"Async Source (Http)";
const AMOVIESETUP_MEDIATYPE sudOpPinTypes =
{
&MEDIATYPE_Stream,
&MEDIASUBTYPE_NULL
};
const AMOVIESETUP_PIN sudOpPin =
{
L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, L"Input", 1, &sudOpPinTypes
};
const AMOVIESETUP_FILTER sudAsyncFile =
{
&CLSID_PIAsyncFile, szAsyncFile, MERIT_UNLIKELY, 1, &sudOpPin };
const AMOVIESETUP_FILTER sudAsyncHttp =
{
&CLSID_PIAsyncHttp, szAsyncHttp, MERIT_UNLIKELY, 1, &sudOpPin };
CFactoryTemplate g_Templates[] =
{
{
szAsyncFile,
&CLSID_PIAsyncFile,
CAsyncFilter::CreateInstance,
NULL,
&sudAsyncFile
},
{
szAsyncHttp,
&CLSID_PIAsyncHttp,
CAsyncFilterHttp::CreateInstance,
NULL,
&sudAsyncHttp
}
};
int g_cTemplates = sizeof(g_Templates) / sizeof(CFactoryTemplate);
sdancer75
modified 21-Jun-13 8:45am.
|
|
|
|
|
Hi, all
I create a new dialog based on MFC (VS2008) without border.
But i found that the dialog without shadow when executing.
how to add the shadow to it.
please help me. thanks
|
|
|
|
|
the style of the dialog is popup
the border is none
|
|
|
|
|
Im using MFC feature pack for my application to create menu bar looks like MS Office.
But is there any option to change the fonst size of text appearing in Ribbon Panel.
I used Add Category, Add Panel and CMFCRibbonButton for buttons in Panel. Just i want to increase the text size in each button.Now it appears very small.
Anu
|
|
|
|
|
Hi,
I am using a slider control on a dialog box. I have handled OnLButtonDown for Slider control. But I wonder its not getting called whenever I click on the slider thumb, instaed it gets called when I click anywhere on the dialog.
I want to handle OnLButtonDown when I click on the slider thumb.
Anybody have any idea where is the issue.?
Any help will be appreciated.
Regards,
Mbatra
|
|
|
|
|
Do you really need a OnLButtonDown on a Slider control? If you just want to handle whenever its value get changed, you can try OnHScroll or OnVScroll instead.
|
|
|
|
|
Hi,
Yes I do need to handle OnLButtonDown.
Scenario is I am using slider control to show the progress of the video. Slider will be incremented in steps in proportion to the time elapsed for the video. Now when I click on the slider and hold for the moment, I need to stop it, otherwise the slider keeps incrementing with the timer while still user is holding the mouse on clicking on its thumb.
So I need to handle this message handler. I have tried in OnHScroll also, it didn't work.
Regards,
Mbatra
|
|
|
|
|
In the OnHScroll, the UINT nSBCode parameter contains the code message. nSBCode == TB_THUMBTRACK when you use the mouse to drag it.
|
|
|
|
|
I had already tried this......NOT WORKING.
just check the same case.....Click on the slider thumb, but don't move the slider. Just click the left button and hold. Slider thumb keeps on moving with the timer and video progression.
I need to left click the mouse button on the slider thumb and handle that message.
Regards,
Mbatra
|
|
|
|
|
I just tried and I get notifications of each move. Code excerpt looks like:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_NOTIFY(TRBN_THUMBPOSCHANGING, IDC_SLIDER1, &CTestDlg::OnTRBNThumbPosChangingSlider1)
END_MESSAGE_MAP()
void CTestDlg::OnTRBNThumbPosChangingSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
NMTRBTHUMBPOSCHANGING *pNMTPC = reinterpret_cast<NMTRBTHUMBPOSCHANGING *>(pNMHDR);
TRACE(_T("Position = %lu\n"), pNMTPC->dwPos);
*pResult = 0;
}
Did you remember to turn on the "Notify Before Move" style?
"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 David,
Thanx for the reply.
Also plz help me to solve one more issue. I want to to move the thumb where user has clicked the mouse, not in ticks.
Slider thumb should move to the position in one shot, user clicked the mouse...
I tried this code.....but it didn't work for me.
CRect rc, trc;
m_Slider.GetChannelRect(rc);
m_Slider.GetThumbRect(trc);
rc.InflateRect(0, (trc.Height() - rc.Height())/2);
if (!PtInRect(rc, point))
return;
LONG range = m_Slider.GetRangeMax();
LONG pos = point.x - rc.left - trc.Width()/2;
LONG width = rc.Width() - trc.Width();
m_Slider.SetPos(int(DOUBLE(pos) * range / width + 0.5));
Please share any sample code if you have.
Regards,
Mbatra
|
|
|
|
|
Try something like:
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CSliderCtrl::OnLButtonDown(nFlags, point);
CRect rectClient;
GetClientRect(rectClient);
CRect rectChannel;
GetChannelRect(rectChannel);
int nPos = (GetRangeMax() - GetRangeMin()) *
(point.x - rectClient.left - rectChannel.left) /
(rectChannel.right - rectChannel.left);
SetPos(nPos);
}
"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
modified 3-Jul-13 10:50am.
|
|
|
|
|
Hi David,
I tried this one also....Still not working.
I had one issue, I don't know but the OnLButtonDown() handler is not getting called anymore. This is happening in case of mine.
That's why I was not able to set the position of the slider.
I have done like this:
void CCapturePage::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rectClient;
GetClientRect(rectClient);
CRect rectChannel;
m_CaptureSlider.GetChannelRect(rectChannel);
int nPos = (m_CaptureSlider.GetRangeMax() - m_CaptureSlider.GetRangeMin()) *
(point.x - rectClient.left - rectChannel.left) /
(rectChannel.right - rectChannel.left);
m_CaptureSlider.SetPos(nPos);
CPropertyPage::OnLButtonDown(nFlags, point);
}
This is a Propery page which is included in a property sheet. On that Dialog box, I am using a slider control.
Does SetCapture() and SetFocus() make any difference in OnLButtonDown().
I don't know why this handler is not getting called.?
Regards,
Mbatra
|
|
|
|
|
mbatra31 wrote: I had one issue, I don't know but the OnLButtonDown() handler is not getting called anymore. Because it is supposed to be in a CSliderCtrl -derived class.
"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 everyone.. I have written the code for encryption algorithm. It has one user function header file also. Sample code is as shown below... I want return {Pa,C1,C2} in the program to main function. Please help me..
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#include <math.h>
#include "FiniteFieldElement.hpp"
namespace Cryptography
{
template<int P>
typedef struct {
Cryptography::EllipticCurve<P>::Point Pa;
Cryptography::FiniteFieldElement<P> c1;
Cryptography::FiniteFieldElement<P> c2;
} encrypt_data_t;
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_;
}
.....
.....
....
...
};
typedef EllipticCurve<P> this_t;
typedef class EllipticCurve<P>::Point point_t;
namespace utils
{
}
using namespace Cryptography;
using namespace utils;
template <int P>
encrypt_data_t<P> my_encrypt()
{
typedef EllipticCurve<263> ec_t;
ec_t myEllipticCurve(1,1);
ec_t::Point Pa = a*G;
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";
encrypt_data_t <263> ret;
ret.Pa = Pa;
ret.c1 = c1;
ret.c2 = c2;
return ret;
}
main()
{
int result;
template <int P>
result = encrypt_data_t<P> my_encrypt();
}
"I want to return {Pa,C1,C2} to the main program using structures... I am getting so many errors"
"Please help me with this problem"
|
|
|
|
|
Quote: I am getting so many errors
I would start fixing them (or post them here if you are unable to).
Veni, vidi, vici.
|
|
|
|
|
These are the errors i am getting for the program
Manoj1.cc:25:17: error: template class without a name
Manoj1.cc:25:9: error: template declaration of ‘typedef’
Manoj1.cc:39:44: error: ‘P’ was not declared in this scope
Manoj1.cc:39:45: error: template argument 1 is invalid
Manoj1.cc:47:37: error: ‘EllipticCurve’ is not a template
Manoj1.cc:47:51: error: ‘P’ was not declared in this scope
Manoj1.cc:49:48: error: ‘P’ was not declared in this scope
Manoj1.cc:49:49: error: template argument 1 is invalid
Manoj1.cc:231:41: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc:231:55: error: ‘P’ was not declared in this scope
Manoj1.cc:243:59: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc:243:73: error: ‘P’ was not declared in this scope
Manoj1.cc:418:25: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc:418:39: error: ‘P’ was not declared in this scope
Manoj1.cc:420:31: error: ‘EllipticCurve’ is not a template
Manoj1.cc:420:45: error: ‘P’ was not declared in this scope
Manoj1.cc:521:36: error: ‘P’ was not declared in this scope
Manoj1.cc:521:37: error: template argument 1 is invalid
Manoj1.cc:525:36: error: ‘P’ was not declared in this scope
Manoj1.cc:525:37: error: template argument 1 is invalid
Manoj1.cc:533:64: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc:549:40: error: ‘P’ was not declared in this scope
Manoj1.cc:549:41: error: template argument 1 is invalid
Manoj1.cc:551:40: error: ‘P’ was not declared in this scope
Manoj1.cc:551:41: error: template argument 1 is invalid
Manoj1.cc: In member function ‘Cryptography::EllipticCurve::Point Cryptography::EllipticCurve::Point::scalarMultiply(int, const Cryptography::EllipticCurve::Point&)’:
Manoj1.cc:90:51: error: call of overloaded ‘Point(int, int, Cryptography::EllipticCurve&)’ is ambiguous
Manoj1.cc:90:51: note: candidates are:
Manoj1.cc:243:21: note: Cryptography::EllipticCurve::Point::Point(const ffe_t&, const ffe_t&, Cryptography::EllipticCurve&)
Manoj1.cc:231:21: note: Cryptography::EllipticCurve::Point::Point(int, int, Cryptography::EllipticCurve&)
Manoj1.cc: In member function ‘void Cryptography::EllipticCurve::Point::add(Cryptography::EllipticCurve::Point::ffe_t, Cryptography::EllipticCurve::Point::ffe_t, Cryptography::EllipticCurve::Point::ffe_t, Cryptography::EllipticCurve::Point::ffe_t, Cryptography::EllipticCurve::Point::ffe_t&, Cryptography::EllipticCurve::Point::ffe_t&) const’:
Manoj1.cc:179:40: error: request for member ‘i’ in ‘x1’, which is of non-class type ‘Cryptography::EllipticCurve::Point::ffe_t {aka int}’
Manoj1.cc:179:47: error: request for member ‘i’ in ‘x1’, which is of non-class type ‘Cryptography::EllipticCurve::Point::ffe_t {aka int}’
Manoj1.cc: In function ‘Cryptography::EllipticCurve::Point Cryptography::operator+(const Cryptography::EllipticCurve::Point&, const Cryptography::EllipticCurve::Point&)’:
Manoj1.cc:364:52: error: call of overloaded ‘Point(Cryptography::EllipticCurve::Point::ffe_t&, Cryptography::EllipticCurve::Point::ffe_t&, Cryptography::EllipticCurve&)’ is ambiguous
Manoj1.cc:364:52: note: candidates are:
Manoj1.cc:243:21: note: Cryptography::EllipticCurve::Point::Point(const ffe_t&, const ffe_t&, Cryptography::EllipticCurve&)
Manoj1.cc:231:21: note: Cryptography::EllipticCurve::Point::Point(int, int, Cryptography::EllipticCurve&)
Manoj1.cc: In member function ‘void Cryptography::EllipticCurve::CalculatePoints()’:
Manoj1.cc:447:31: error: ‘P’ was not declared in this scope
Manoj1.cc:457:25: error: ‘x_val’ was not declared in this scope
Manoj1.cc:457:50: error: request for member ‘i’ in ‘((Cryptography::EllipticCurve*)this)->Cryptography::EllipticCurve::a_’, which is of non-class type ‘int’
Manoj1.cc:457:63: error: request for member ‘i’ in ‘((Cryptography::EllipticCurve*)this)->Cryptography::EllipticCurve::b_’, which is of non-class type ‘int’
Manoj1.cc:459:25: error: ‘y_val’ was not declared in this scope
Manoj1.cc:473:34: error: ‘x_val’ was not declared in this scope
Manoj1.cc:473:46: error: ‘y_val’ was not declared in this scope
Manoj1.cc:477:67: error: call of overloaded ‘Point(int&, int&, Cryptography::EllipticCurve&)’ is ambiguous
Manoj1.cc:477:67: note: candidates are:
Manoj1.cc:243:21: note: Cryptography::EllipticCurve::Point::Point(const ffe_t&, const ffe_t&, Cryptography::EllipticCurve&)
Manoj1.cc:231:21: note: Cryptography::EllipticCurve::Point::Point(int, int, Cryptography::EllipticCurve&)
Manoj1.cc: In member function ‘int Cryptography::EllipticCurve::Degree() const’:
Manoj1.cc:517:49: error: ‘P’ was not declared in this scope
Manoj1.cc: At global scope:
Manoj1.cc:561:22: error: expected nested-name-specifier before ‘EllipticCurve’
Manoj1.cc:561:35: error: expected initializer before ‘<’ token
Manoj1.cc:567:49: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc: In function ‘std::ostream& Cryptography::operator<<(std::ostream&, const Cryptography::EllipticCurve&)’:
Manoj1.cc:583:35: error: request for member ‘i’ in ‘EllipticCurve.b_’, which is of non-class type ‘const int’
Manoj1.cc: At global scope:
Manoj1.cc:603:34: error: expected initializer before ‘<’ token
Manoj1.cc:685:1: error: ‘Cryptography::EllipticCurve’ is not a template
Manoj1.cc:685:23: error: expected initializer before ‘my_encrypt’
Manoj1.cc:856:11: error: ‘::main’ must return ‘int’
Manoj1.cc: In function ‘int main()’:
Manoj1.cc:859:3: error: a template declaration cannot appear at block scope
Manoj1.cc:861:2: error: expected ‘;’ before ‘}’ token
The complete program is
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#include <math.h>
#include "FiniteFieldElement.hpp"
namespace Cryptography
{
template<int p="">
typedef struct {
Cryptography::EllipticCurve::Point Pa;
Cryptography::FiniteFieldElement c1;
Cryptography::FiniteFieldElement c2;
} encrypt_data_t;
class EllipticCurve
{
public:
typedef FiniteFieldElement ffe_t;
class Point
{
friend class EllipticCurve ;
typedef FiniteFieldElement 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; // doubling step
}
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;
}
// the additions
ffe_t s;
if ( x1 == x2 && y1 == y2 )
{
//2P
s = (3*(x1.i()*x1.i()) + ec_->a()) / (2*y1);
xR = ((s*s) - 2*x1);
}
else
{
//P+Q
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 & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
Point(const ffe_t& x, const ffe_t& y, EllipticCurve & EllipticCurve)
: x_(x),
y_(y),
ec_(&EllipticCurve)
{}
public:
static Point ONE;
// copy ctor
Point(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
}
// assignment
Point& operator=(const Point& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
ec_ = rhs.ec_;
return *this;
}
// access x component as element of Fp
ffe_t x() const { return x_; }
// access y component as element of Fp
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;
}
// negate
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_);
}
// a + b
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_);
}
// a * int
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;
}
// a *= int
Point& operator*=(int k)
{
return (*this = scalarMultiply(k,*this));
}
// ostream handler: print this point
friend ostream& operator <<(ostream& os, const Point& p)
{
return (os << "(" << p.x_ << ", " << p.y_ << ")");
}
};
// ==================================================== EllipticCurve impl
typedef EllipticCurve this_t;
typedef class EllipticCurve ::Point point_t;
// ctor
// Initialize EC as y^2 = x^3 + ax + b
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;
}
// get a point (group element) on the curve
Point operator[](int n)
{
if ( !table_filled_ )
{
CalculatePoints();
}
return m_table_[n];
}
// number of elements in this group
size_t Size() const { return m_table_.size(); }
// the degree P of this EC
int Degree() const { return P; }
// the parameter a (as an element of Fp)
FiniteFieldElement a() const { return a_; }
// the paramter b (as an element of Fp)
FiniteFieldElement b() const { return b_; }
// ostream handler: print this curve in human readable form
template<int t="">
friend ostream& operator <<(ostream& os, const EllipticCurve<t>& EllipticCurve);
// print all the elements of the EC group
ostream& PrintTable(ostream &os, int columns=4);
private:
typedef std::vector<point> m_table_t;
m_table_t m_table_; // table of points
FiniteFieldElement a_; // paramter a of the EC equation
FiniteFieldElement b_; // parameter b of the EC equation
bool table_filled_; // true if the table has been calculated
};
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 ::PrintTable(ostream &os, int columns)
{
if ( table_filled_ )
{
int col = 0;
typename EllipticCurve ::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;
template <int p="">
EllipticCurve ec_t my_encrypt()
{
// template <int p="">
//encrypt_data_t my_encrypt();
typedef EllipticCurve<263> ec_t;
ec_t myEllipticCurve(1,1);
cout << "A little Elliptic Curve cryptography example\nby Jarl Ostensen, 2007\n\n";
// print out a little info and test some properties
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";
// Alice
int a = irand(1,myEllipticCurve.Degree()-1);
ec_t::Point Pa = a*G; // public key
cout << "Alice' public key Pa = " << a << "*" << G << " = " << Pa << endl;
// Bob
int b = irand(1,myEllipticCurve.Degree()-1);;
ec_t::Point Pb = b*G; // public key
cout << "Bob's public key Pb = " << b << "*" << G << " = " << Pb << endl;
// Jane, the eavesdropper
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 = 19;
int m2 = 72;
cout << "Plain text message from Alice to Bob: (" << m1 << ", " << m2 << ")\n";
// encrypt using Bob`s key
ec_t::Point Pk = a*Pb;
ec_t::ffe_t c1( m1*Pk.x() );
ec_t::ffe_t c2( m2*Pk.y() );
// encrypted message is: Pa,c1,c2
cout << "Encrypted message from Alice to Bob = {Pa,c1,c2} = {" << Pa << ", " << c1 << ", " << c2 << "}\n\n";
encrypt_data_t <263> ret;
ret.Pa = Pa;
ret.c1 = c1;
ret.c2 = c2;
return ret;
// Bob now decrypts Alice`s message, using her public key and his session integer "b" which was also used to generate his public key
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;
// Jane intercepts the message and tries to decrypt it using her key
Pk = j*Pa;
m1d = c1/Pk.x();
m2d = c2/Pk.y();
cout << "\nJane's decrypted message from Alice = (" << m1d << ", " << m2d << ")" << endl;
cout << endl;
}
void main()
{
int result;
template <int p="">
result = encrypt_data_t my_encrypt();
}
|
|
|
|
|
I think that confirms my comment to you about the use of namespaces and templates.
Use the best guess
|
|
|
|
|
Get rid of all your templates and namespaces, they serve no purpose.
Use the best guess
|
|
|
|
|