📄 cryptimpl.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 + -