-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitcryto.cpp
More file actions
48 lines (37 loc) · 847 Bytes
/
bitcryto.cpp
File metadata and controls
48 lines (37 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 模块描述:简单的移位加密算法
//----------------------------------------------------------------*/
#include <string>
#include "bitcryto.h"
using std::string;
CBitCryto::CBitCryto(const char* szKey) : m_strKey(szKey), m_nIdx(0)
{
}
CBitCryto::~CBitCryto()
{
}
unsigned char CBitCryto::Encode(unsigned char c)
{
if(m_nIdx >= m_strKey.size())
{
m_nIdx = 0;
}
unsigned short k = (unsigned short)m_strKey[m_nIdx];
++m_nIdx;
unsigned char c2 = (unsigned char)((k + (unsigned short)c) & 0xff);
return c2;
}
unsigned char CBitCryto::Decode(unsigned char c)
{
if(m_nIdx >= m_strKey.size())
{
m_nIdx = 0;
}
short k = (short)m_strKey[m_nIdx];
++m_nIdx;
short c2 = (short)c - k;
if(c2 < 0)
{
c2 += 256;
}
return (unsigned char)c2;
}