euclid.cpp

来自「MFC下实现的仿射密码算法」· C++ 代码 · 共 47 行

CPP
47
字号
// Euclid.cpp: implementation of the Euclid class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "affine.h"
#include "Euclid.h"
#include <math.h>

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Euclid::Euclid()
{
	
}

Euclid::~Euclid()
{

}
int Euclid::Backspin(int d)
{
	int Q;
	int t1,t2,t3;
	int x1=1,x2=0,x3=26;
	int y1=0,y2=1,y3=d;
	while (y3!=1&&y3!=0) {
		div_t div_quot;
	    div_quot=div(x3,y3);
		Q=div_quot.quot;
		t1=x1-Q*y1; t2=x2-Q*y2; t3=x3-Q*y3;
		x1=y1; x2=y2; x3=y3;
		y1=t1; y2=t2; y3=t3;
	}
	if (y3==0) { return D=0;}
	if (y3==1) {
		if (y2<0) {	y2=y2+26;}
		return D=y2;
	}    
 }

⌨️ 快捷键说明

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