32 'b',
'c',
'e',
'a',
'f',
'g',
'i',
'j',
'k',
'l',
33 'h',
'm',
'p',
'q',
'B',
'r',
'H',
'o',
's',
't',
34 'T',
'u',
'w',
'x',
'y',
'A',
'd',
'C',
'D',
'z',
35 'E',
'F',
'I',
'J',
'K',
'G',
'L',
'N',
'O',
'7',
36 'P',
'Q',
'M',
'R',
'S',
'U',
'V',
'W',
'X',
'Y',
37 '9',
'0',
'1',
'2',
'Z',
'3',
'6',
'4',
'n',
'8',
80 memcpy(
buf, ibuf, ilen);
102 memcpy(
buf, ibuf, *ilen);
116 if (ilen) *ilen =
len;
134 for (
unsigned long i = 0; i <
len; i++)
154 for (i = 0; i <
len; i++)
181 std::map<char, int> charHash;
182 for (
int i = 0; i < 62; ++i) charHash[lats[i]] = i;
186 for (
unsigned int i = 0; i < buf.
size() && segn < 5; ++i) {
187 if (buf[i] ==
'-') ++segn;
188 else segs[segn].
append(buf[i]);
191 SWBuf chkSum = segs[4];
192 if (segs[4].
size() < 5) segs[4].
size(4);
193 for (
int i = 0; i < 4; ++i) {
195 for (
unsigned int j = 0; j < segs[i].
size() && j < segs[0].
size(); ++j) {
196 char hash = charHash[segs[i][j]];
197 char obfusHash = charHash[segs[0][j%segs[0].size()]];
199 obfusHash = hash - (i ? obfusHash : 0);
200 if (obfusHash < 0) obfusHash = (62 + obfusHash);
203 obfusHash = hash + (i ? obfusHash : 0);
206 if (i) segs[i][j] = lats[(long)obfusHash];
207 csum += (encode ? obfusHash : hash);
209 segs[4][i] = lats[csum%62];
210 if (result.
size()) result +=
"-";
211 result += (!encode && !i ?
"" : segs[i].
c_str());
217 return (!encode && chkSum != segs[4]) ? buf :
result;
#define SWORD_NAMESPACE_START
SWCipher(unsigned char *key)
virtual void decode(void)
unsigned char encrypt(unsigned char b=0)
virtual void setCipherKey(const char *key)
virtual void encode(void)
virtual void setCipheredBuf(unsigned long *len, const char *buf=0)
const char * c_str() const
SWBuf & append(const char *str, long max=-1)
void initialize(unsigned char *key, unsigned char keysize)
virtual char * getCipheredBuf(unsigned long *len=0)
virtual void setUncipheredBuf(const char *buf=0, unsigned long len=0)
unsigned long size() const
static SWBuf personalize(const SWBuf &buf, bool encode)
unsigned char decrypt(unsigned char b)
virtual char * getUncipheredBuf()
#define SWORD_NAMESPACE_END