llrsa.cpp

来自「rsa加密算法很好的例子」· C++ 代码 · 共 79 行

CPP
79
字号
// LLrsa.cpp: implementation of the CLLrsa class.
//
//////////////////////////////////////////////////////////////////////

#include <iostream.h>

#include "LLrsa.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLLrsa::CLLrsa()
{

	head = 0; // no elements in start
	tail = 0;
}

CLLrsa::~CLLrsa()
{

}

bool CLLrsa::insert(long e,long v)
{

	//create a new element
	CLLrsaNode *temp = new CLLrsaNode();
	temp->eValue = e;
	temp->value = v;

	if (head == 0)
	{ //insert the first element
		head = tail = temp;
	}
	else 
	{
		tail->next = temp;
		temp->prev = tail;

		tail = temp;
	}

	return true;
}

//print all values
void CLLrsa::print()
{
	CLLrsaNode *temp = head;

	while(temp != 0) {
		cout << endl << temp->eValue << ":" << temp->value;
		temp = temp->next;
	}

}

// calculate which exponent should be added now
long CLLrsa::getNextToAdd(long &mye_add,long mye,long e)
{
	CLLrsaNode *temp = tail;

	while(temp != 0)
	{
		if (temp->eValue + mye <= e)
		{
			mye_add = temp->eValue;
			return temp->value;
		}

		temp = temp->prev;
	}

	mye_add = 1;
	return head->value;
}

⌨️ 快捷键说明

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