• 大小: 14.58M
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2023-07-08
  • 语言: 其他
  • 标签: 其他  

资源简介

TEAcode.rar

资源截图

代码片段和文件信息

#include “tea.h“
#include  //for memcpymemset

using namespace std;

TEA::TEA(const byte *key int round /*= 32*/ bool isNetByte /*= false*/)
:_round(round)
_isNetByte(isNetByte) {
if (key != 0)
memcpy(_key key 16);
else
memset(_key 0 16);
}

TEA::TEA(const TEA &rhs)
:_round(rhs._round)
_isNetByte(rhs._isNetByte) {
memcpy(_key rhs._key 16);
}

TEA& TEA::operator=(const TEA &rhs) {
if (&rhs != this) {
_round = rhs._round;
_isNetByte = rhs._isNetByte;
memcpy(_key rhs._key 16);
}
return *this;
}

void TEA::encrypt(const byte *in byte *out) {
encrypt((const ulong*)in (ulong*)out);
}

void TEA::decrypt(const byte *in byte *out) {
decrypt((const ulong*)in (ulong*)out);
}

void TEA::encrypt(const ulong *in ulong *out) {

ulong *k = (ulong*)_key;
register ulong y = ntoh(in[0]);
register ulong z = ntoh(in[1]);
register ulong a = ntoh(k[0]);
register ulong b = ntoh(k[1]);
register ulong c = ntoh(k[2]);
register ulong d = ntoh(k[3]);
register ulong delta = 0x9E3779B9; /* (sqrt(5)-1)/2*2^32 */
register int round = _round;
register ulong sum = 0;

while (round--) {    /* basic cycle start */
sum += delta;
y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
}    /* end cycle */
out[0] = ntoh(y);
out[1] = ntoh(z);
}

void TEA::decrypt(const ulong *in ulong *out) {

ulong *k = (ulong*)_key;
register ulong y = ntoh(in[0]);
register ulong z = ntoh(in[1]);
register ulong a = ntoh(k[0]);
register ulong b = ntoh(k[1]);
register ulong c = ntoh(k[2]);
register ulong d = ntoh(k[3]);
register ulong delta = 0x9E3779B9; /* (sqrt(5)-1)/2*2^32 */
register int round = _round;
register ulong sum = 0;

if (round == 32)
sum = 0xC6EF3720; /* delta << 5*/
else if (round == 16)
sum = 0xE3779B90; /* delta << 4*/
else
sum = delta << static_cast(logbase(2 round));

while (round--) {    /* basic cycle start */
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
sum -= delta;
}    /* end cycle */
out[0] = ntoh(y);
out[1] = ntoh(z);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      71680  2014-04-11 14:14  TEAcode\Debug\TEAcode.exe

     文件     522160  2014-04-11 14:14  TEAcode\Debug\TEAcode.ilk

     文件     814080  2014-04-11 14:14  TEAcode\Debug\TEAcode.pdb

     文件   46137344  2014-04-11 14:14  TEAcode\ipch\teacode-5726293e\teacode-224582c1.ipch

     文件       2044  2014-04-11 14:14  TEAcode\TEAcode\Debug\cl.command.1.tlog

     文件      55286  2014-04-11 14:14  TEAcode\TEAcode\Debug\CL.read.1.tlog

     文件       1092  2014-04-11 14:14  TEAcode\TEAcode\Debug\CL.write.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link-cvtres.read.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link-cvtres.write.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.8080-cvtres.read.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.8080-cvtres.write.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.8080.read.1.tlog

     文件          2  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.8080.write.1.tlog

     文件       1754  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.command.1.tlog

     文件       4040  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.read.1.tlog

     文件        892  2014-04-11 14:14  TEAcode\TEAcode\Debug\link.write.1.tlog

     文件        374  2014-04-11 14:14  TEAcode\TEAcode\Debug\mt.command.1.tlog

     文件        402  2014-04-11 14:14  TEAcode\TEAcode\Debug\mt.read.1.tlog

     文件        298  2014-04-11 14:14  TEAcode\TEAcode\Debug\mt.write.1.tlog

     文件        508  2014-04-11 14:14  TEAcode\TEAcode\Debug\rc.command.1.tlog

     文件        374  2014-04-11 14:14  TEAcode\TEAcode\Debug\rc.read.1.tlog

     文件        278  2014-04-11 14:14  TEAcode\TEAcode\Debug\rc.write.1.tlog

     文件      53971  2014-04-11 14:12  TEAcode\TEAcode\Debug\tea.obj

     文件        406  2014-04-11 14:14  TEAcode\TEAcode\Debug\TEAcode.exe.embed.manifest

     文件        472  2014-04-11 14:14  TEAcode\TEAcode\Debug\TEAcode.exe.embed.manifest.res

     文件        381  2014-04-11 14:14  TEAcode\TEAcode\Debug\TEAcode.exe.intermediate.manifest

     文件         55  2014-04-11 14:14  TEAcode\TEAcode\Debug\TEAcode.lastbuildstate

     文件       2926  2014-04-11 14:14  TEAcode\TEAcode\Debug\TEAcode.log

     文件        204  2014-04-11 14:12  TEAcode\TEAcode\Debug\TEAcode_manifest.rc

     文件     122926  2014-04-11 14:14  TEAcode\TEAcode\Debug\test.obj

............此处省略23个文件信息

评论

共有 条评论