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

📄 m_elg.cpp

📁 基于ElGamal的数字签名系统可以对报文在不同的密钥长度上进行签名与验证.
💻 CPP
字号:
// M_ELG.cpp : implementation file
//

#include "stdafx.h"
#include "forward_secure.h"
#include "M_ELG.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// M_ELG dialog


M_ELG::M_ELG(CWnd* pParent /*=NULL*/)
	: CDialog(M_ELG::IDD, pParent)
{
	//{{AFX_DATA_INIT(M_ELG)
	m_Va = _T("");
	m_Vb = _T("");
	m_l = _T("");
	m_r = _T("");
	m_Vm = _T("");
	//}}AFX_DATA_INIT
}


void M_ELG::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(M_ELG)
	DDX_Text(pDX, IDC_EDITa, m_Va);
	DDX_Text(pDX, IDC_EDITb, m_Vb);
	DDX_Text(pDX, IDC_EDITL, m_l);
	DDX_Text(pDX, IDC_EDITR, m_r);
	DDX_Text(pDX, IDC_EDITM, m_Vm);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(M_ELG, CDialog)
	//{{AFX_MSG_MAP(M_ELG)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// M_ELG message handlers

void M_ELG::OnButton2()   //签名
{
	// TODO: Add your control notification handler code here
    char buffer[9];
	CString stemp;
    CBigInt d,deuc,temp,temp2;
    M.m_ulValue[0]=0xbacfb7ca;  //合肥
    M.m_ulValue[1]=0xb9a4d2b5;  //工业
	M.m_ulValue[2]=0xb4f3d1a7;  //大学
	M.m_nLength=3;
	
	
	d.GetPrime(t_length);
	a=g.RsaTrans(d,p);     //g^ d mod p
	deuc=d.Euc(p.Sub(1));  //d^-1 mod p-1
	temp2=a.Mul(s);        //a*s  
	temp2=temp2.Mod(p.Sub(1));  //a*s mod p-1
	temp=M.Add(p.Sub(1));       //M + (p-1)
    temp=temp.Sub(temp2);       //M-a*s
	temp=temp.Mod(p.Sub(1));    //(M-a*s) mod p-1
	temp=deuc.Mul(temp);        //d^-1[M-a*s] 
	b=temp.Mod(p.Sub(1));       //d^-1[M-a*s] mod p-1

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');
   UpdateData(false);     //显示到文本筐
	
}

void M_ELG::OnButton1()     //验证
{
	// TODO: Add your control notification handler code here
    char buffer[9];
	CString stemp;
    CBigInt left,right,y,temp1,temp2;
	int succ1;
	y=g.RsaTrans(s,p);   //y=g^x mod p
	
	temp1=y.RsaTrans(a,p); //y^a mod p
	temp2=a.RsaTrans(b,p); //a^b mod p
	left=temp1.Mul(temp2); //left=y^a * a^b
	left=left.Mod(p);      //left mod p
	right=g.RsaTrans(M,p); //g^m mod p
	 

  for(int i=left.m_nLength-1;i>=0;i--)
	{
       _ltoa( left.m_ulValue[i], buffer, 16 );
       stemp.Format("%8s",buffer);       
       m_l+=stemp;
	}
   m_l.Replace (' ','0');
   //
   for( i=right.m_nLength-1;i>=0;i--)
	{
       _ltoa( right.m_ulValue[i], buffer, 16 );
       stemp.Format("%8s",buffer);       
       m_r+=stemp;
	}
   m_r.Replace (' ','0');
   UpdateData(false);



	
}

BOOL M_ELG::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Vm="合肥工业大学";
    UpdateData(false);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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