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

📄 emod.cpp

📁 1024位的大整数进行相乘(N方)取模
💻 CPP
字号:
#include "StdAfx.h"
#include ".\emod.h"
#include <string.h>

EMod::EMod(void)
: m_strOutput(NULL)
{
}

EMod::~EMod(void)
{
}

void EMod::emod(char* a, char* e, char* n, char* result)
{
	char temp[MAXLENGTH];
	mm.reverse(a);
	mm.reverse(e);
	mm.reverse(n);
	strcpy( result,a );
	int e_length=mm.length(e);
	for( int i=e_length-1;i>0;i-- ){
		result[ mm.length(result) ]=0;
		strcpy( temp,result );
		mm.cmod( temp,temp,n, result);
		if( e[i-1]=='1' ){
			result[ mm.length(result) ]=0;
			strcpy( temp,result );
			mm.cmod( temp,a,n,result);
		}
	}
}

void EMod::showemod(char* a, char* e, char* n, char* result){
	*m_strOutput=_T("");
	
	char temp[MAXLENGTH];
	mm.reverse(a);
	mm.reverse(e);
	mm.reverse(n);
	
	(*m_strOutput).Append( "A Mod N\r\n" );
	strcpy( temp,a);
	mm.mod( temp,n,strlen(temp) );
	temp[ mm.length( temp ) ]=0;
	mm.reverse( temp );
	(*m_strOutput).Append( temp);
	(*m_strOutput).Append( "\r\n");
	(*m_strOutput).Append( "\r\n");

	strcpy( result,a );
	int e_length=mm.length(e);
	for( int i=e_length-1;i>0;i-- ){
		result[ mm.length(result) ]=0;
		strcpy( temp,result );
		mm.cmod( temp,temp,n, result);
		(*m_strOutput).Append(_T("A^"));

		for( int j=e_length-1;j>=i;j-- ){
			(*m_strOutput)+=e[j];
		}
		(*m_strOutput).Append( _T("0 Mod N:\r\n") );
		strcpy( temp,result );
		temp[ mm.length( temp ) ]=0;
		mm.reverse( temp );
		(*m_strOutput).Append( temp);
		(*m_strOutput).Append( "\r\n");
		(*m_strOutput).Append( "\r\n");


		if( e[i-1]=='1' ){
			result[ mm.length(result) ]=0;
			strcpy( temp,result );
			mm.cmod( temp,a,n,result);

			(*m_strOutput).Append(_T("A^"));
			for( int j=e_length-1;j>=i;j-- ){
			(*m_strOutput)+=e[j];
			}
			(*m_strOutput).Append( _T("1 Mod N:\r\n") );
			strcpy( temp,result );
			temp[ mm.length( temp ) ]=0;
			mm.reverse( temp );
			(*m_strOutput).Append( temp);
			(*m_strOutput).Append( "\r\n");
			(*m_strOutput).Append( "\r\n");
		}
	}
}

⌨️ 快捷键说明

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