⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 si_ver.cpp

📁 ElGamal 数字签名源码
💻 CPP
字号:
// si_ver.cpp : implementation file
//

#include "stdafx.h"
#include "forward_secure.h"
#include "si_ver.h"
#include "stdlib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// si_ver dialog


si_ver::si_ver(CWnd* pParent /*=NULL*/)
	: CDialog(si_ver::IDD, pParent)
{
	//{{AFX_DATA_INIT(si_ver)
	m_Vm = _T("");
	m_Va = _T("");
	m_Vb = _T("");
	m_Vi = 0;
	m_Vri = _T("");
	m_Vet = 0.0;
	m_Vthis = 0.0;
	m_Vsint = 0.0;
	
	//}}AFX_DATA_INIT
}


void si_ver::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(si_ver)
	DDX_Control(pDX, IDC_BUTTONsin, m_Csin);
	DDX_Control(pDX, IDC_BUTTONres, m_Cres);
	DDX_Control(pDX, IDC_COMBOi, m_CCi);
	DDX_Control(pDX, IDC_BUTTONthis, m_Bthis);
	DDX_Control(pDX, IDC_BUTTONet, m_Bet);
	DDX_Text(pDX, IDC_EDITM, m_Vm);
	DDX_Text(pDX, IDC_EDITa, m_Va);
	DDX_Text(pDX, IDC_EDITb, m_Vb);
	DDX_Text(pDX, IDC_EDITi, m_Vi);
	DDX_Text(pDX, IDC_EDITri, m_Vri);
	DDX_Text(pDX, IDC_EDITet, m_Vet);
	DDX_Text(pDX, IDC_EDITthis, m_Vthis);
	DDX_Text(pDX, IDC_EDITsin, m_Vsint);
	DDX_CBString(pDX, IDC_COMBOi, m_CVi);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(si_ver, CDialog)
	//{{AFX_MSG_MAP(si_ver)
	ON_BN_CLICKED(IDC_BUTTONres, OnBUTTONres)
	ON_BN_CLICKED(IDC_BUTTONet, OnBUTTONet)
	ON_BN_CLICKED(IDC_BUTTONthis, OnBUTTONthis)
	ON_BN_CLICKED(IDC_BUTTONkeysure, OnBUTTONkeysure)
	ON_BN_CLICKED(IDC_BUTTONsin, OnBUTTONsin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// si_ver message handlers

BOOL si_ver::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Vm="合肥工业大学";
    UpdateData(true);
	m_Bet.EnableWindow(false);
	m_Bthis.EnableWindow(false);
    m_Csin.EnableWindow(false);
	m_Cres.EnableWindow(false);
	m_CCi.SetCurSel (0);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void si_ver::OnBUTTONres() 
{
	// TODO: Add your control notification handler code here
	 LARGE_INTEGER litmp;
	LONGLONG QPart1,QPart2;
	double dfMinus,dfFreq,dfTim;
	QueryPerformanceFrequency(&litmp);
	//获得计数器的时钟频率d
	dfFreq=(double)litmp.QuadPart;
	CBigInt d,deuc,temp,temp2;
	char buffer[9];
	CString stemp;
	
    M.m_ulValue[0]=0xbacfb7ca;
    M.m_ulValue[1]=0xb9a4d2b5;
	M.m_ulValue[2]=0xb4f3d1a7;
	M.m_nLength=3;
	QueryPerformanceCounter(&litmp);
		//获得初始值
	QPart1 = litmp.QuadPart;
	d.GetPrime(t_length);
	a=g.RsaTrans(d,p);
	deuc=d.Euc(p.Sub(1));
	temp2=a.Mul(temps);
	temp2=temp2.Mod(p.Sub(1));
	temp=M.Add(p.Sub(1));
    temp=temp.Sub(temp2);
	temp=temp.Mod(p.Sub(1));
	temp=deuc.Mul(temp);
	b=temp.Mod(p.Sub(1));
    QueryPerformanceCounter(&litmp); 
	//获得终止值 
	QPart2=litmp.QuadPart;
	dfMinus=(double)(QPart2-QPart1);
	dfTim=dfMinus/dfFreq;
	m_Vsint=dfTim;

    for(int i=a.m_nLength-1;i>=0;i--)
	{
       _ltoa( a.m_ulValue[i], buffer, 16 );
       stemp.Format("%8s",buffer);       
       m_Va+=stemp;
	}
   m_Va.Replace (' ','0');
   //
   for( i=b.m_nLength-1;i>=0;i--)
	{
       _ltoa( b.m_ulValue[i], buffer, 16 );
       stemp.Format("%8s",buffer);       
       m_Vb+=stemp;
	}
   m_Vb.Replace (' ','0');
   //
   for( i=tempR.m_nLength-1;i>=0;i--)
	{
       _ltoa(tempR.m_ulValue[i], buffer, 16 );
       stemp.Format("%8s",buffer);       
       m_Vri+=stemp;
	}
   m_Vri.Replace (' ','0');
   //
       
   //_ltoa( timemark, buffer, 10 );
   //stemp.Format("%s",buffer);       
    m_Vi=tempi;
	
   UpdateData(false);
   m_Bet.EnableWindow(true);
   m_Bthis.EnableWindow(true);
}

void si_ver::OnBUTTONet() 
{
	// TODO: Add your control notification handler code here
	//DWORD dwStart1, dwStop1,duration1; 
    LARGE_INTEGER litmp;
	LONGLONG QPart1,QPart2;
	double dfMinus,dfFreq,dfTim;
	QueryPerformanceFrequency(&litmp);
	//获得计数器的时钟频率d
	dfFreq=(double)litmp.QuadPart;
	CBigInt left,right,epk,temp1,temp2;
	int succ1;
	epk=g.RsaTrans(temps,p);
	QueryPerformanceCounter(&litmp);
		//获得初始值
	QPart1 = litmp.QuadPart;
	//dwStart1=GetTickCount(); 
	temp1=epk.RsaTrans(a,p);
	temp2=a.RsaTrans(b,p);
	left=temp1.Mul(temp2);
	left=left.Mod(p);
	right=g.RsaTrans(M,p);
	succ1=left.Cmp(right);
	QueryPerformanceCounter(&litmp); 
	//获得终止值 
	QPart2=litmp.QuadPart;
	dfMinus=(double)(QPart2-QPart1);
	dfTim=dfMinus/dfFreq;
	//dwStop1=GetTickCount(); 
	//duration1=dwStop1-dwStart1;

	if(succ1==0) 
     m_Vet=dfTim*1000;  
     //m_Vet=duration1;
	UpdateData(false);

}

void si_ver::OnBUTTONthis() 
{
	// TODO: Add your control notification handler code here
	//DWORD dwStart2, dwStop2,duration2; 
	LARGE_INTEGER litmp;
	LONGLONG QPart1,QPart2;
	double dfMinus,dfFreq,dfTim;
	QueryPerformanceFrequency(&litmp);
	//获得计数器的时钟频率d
	dfFreq=(double)litmp.QuadPart;
	//获得初始值
	CBigInt left,right,temp1,temp2,temp;
	int succ2;
    //dwStart2=GetTickCount(); 
	QueryPerformanceCounter(&litmp);
		//获得初始值
	QPart1 = litmp.QuadPart;
	right=g.RsaTrans(M,p);
	temp1.Mov(2);//=tempR.Mul(tempR);
	temp1=tempR.RsaTrans(temp1,p);
	temp.Mov(tempi*(tempi+1)/2);
	temp=g.RsaTrans(temp,p);
	/*temp.Mov(g);
	for(int i=1;i<tempi*(tempi+1)/2;i++)
	{	 
		temp=temp.Mul(temp);
	    temp=temp.Mod(p);
	}*/
	
	temp1=temp.Mul(temp1);
	temp1=temp1.Mod(p);
	temp1=temp1.Mul(PK);
	temp1=temp1.Mod(p);
	temp1=temp1.RsaTrans(a,p);
	//temp1=temp1.Mod(p);
	temp2=a.RsaTrans(b,p);
	left=temp1.Mul(temp2);
	left=left.Mod(p);
	right=right.Mod(p);
	succ2=left.Cmp(right);
	//dwStop2=GetTickCount(); 
	//duration2=dwStop2-dwStart2;
	QueryPerformanceCounter(&litmp); 
	//获得终止值 
	QPart2=litmp.QuadPart;
	dfMinus=(double)(QPart2-QPart1);
	dfTim=dfMinus/dfFreq;
	if(succ2==0) 
     m_Vthis=dfTim*1000;
		//m_Vthis=duration2;
	UpdateData(false);

}

void si_ver::OnBUTTONkeysure() 
{
	// TODO: Add your control notification handler code here
	int numi;
	UpdateData(true);
	numi=atoi(m_CVi);
    CBigInt temp1,temp2;
    tempk.Mov(k);
    tempR.Mov(R);
    temps.Mov(s);
    tempi=timemark;
    for(int i=1;i<numi;i++)
	{
	  tempi++;
	  
	  do{
        temp1=g.RsaTrans(tempk,p);
		tempR=tempR.Mul(temp1);
		tempR=tempR.Mod(p);
		temp2=tempR.Mul(tempR);
        temp2=temp2.Mod(p);
		temps=tempk.Add(tempk);
        temps=temps.Add(tempi);
        temps=temps.Add(s);
		temps=temps.Mod(p.Sub(1));
		tempk=tempk.Mul(tempk);
		tempk=tempk.Mod(q);
	  }
	while((temps.m_nLength==1&&temps.m_ulValue[0]==0)
		||(temp1.m_nLength==1&&temp1.m_ulValue[0]==1)
		||(temp2.m_nLength==1&&temp2.m_ulValue[0]==1));
    
	}
    
	m_Va = _T("");
	m_Vb = _T("");
	m_Vi = 0;
	m_Vri = _T("");
	m_Vet = 0.0;
	m_Vthis = 0.0;
	m_Vsint = 0.0;
	m_Cres.EnableWindow(true);
    m_Csin.EnableWindow(true);
    UpdateData(false);

}

void si_ver::OnBUTTONsin() 
{
	// TODO: Add your control notification handler code here
	UpdateData(false);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -