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

📄 cryptimpl.h

📁 crypt_service源码,很值得研究!下来看看就知道!
💻 H
字号:
// Codeproject: A simple C++ client/server application with CORBA// Module: cryptimpl.h// Description: Servant implementation#include "OB/CORBA.h"
#include "crypt_skel.h"
#include <iostream>
#include <string>

class CryptographicImpl : virtual public ::POA_CaesarAlgorithm,
								virtual public PortableServer::RefCountServantBase
							
{			
	
	int cs; // Critical section flag
	public:
		CryptographicImpl():cs(0){}

		// Caesar text encryption algorithm
		::CaesarAlgorithm::charsequence* encrypt(const char* info,::CORBA::ULong k,::CORBA::ULong shift) 
			throw(::CORBA::SystemException)
		{
			cs++;
			std::cout << "request in critical section=" << cs << std::endl;
			std::string msg = info;
			int len = msg.length();
			::CaesarAlgorithm::charsequence* outseq = new ::CaesarAlgorithm::charsequence;
			outseq->length(len + 1);
			std::string::iterator i = msg.begin();
			std::string::iterator end = msg.end();
			int j = 0;
			while (i != end)
			{
				 *i+= shift;
				 *i ^= k;
				 (*outseq)[j++] = *i++;
			}
			(*outseq)[len] = '\0';
			cs--;
			return outseq;

		}
			
		
		// Caesar text decryption algorithm
		char* decrypt(const ::CaesarAlgorithm::charsequence& info,::CORBA::ULong k,::CORBA::ULong shift) 
			throw(::CORBA::SystemException)
		{
			char* r = CORBA::string_alloc(info.length());
	
			for (int i = 0;i < info.length() - 1;i++)
			{				
				r[i]  = info[i];
				r[i] ^= k;
				r[i] -= shift;
				 
			}
			r[info.length() - 1] = '\0';
			return r;
		}	
  
};

⌨️ 快捷键说明

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