YT88加密狗 增强算法(TEA算法) c#开发源代码
本帖最后由 teety 于 2015-12-27 03:47 编辑//公共函数说明
//***查找加密锁
//int FindPort(int start, ref string OutKeyPath);
//查找指定的加密锁(使用普通算法一)
//int FindPort_2(int start, int in_data, int verf_data, ref string OutKeyPath);
//***获到锁的版本
//int NT_GetIDVersion(ref short version,string KeyPath);
//获到锁的扩展版本
//int NT_GetIDVersionEx(ref short version,string KeyPath);
//***获到锁的ID
//int GetID(ref int id_1, ref int id_2, string KeyPath);
//***从加密锁中读取一批字节
//int YReadEx(byte[] OutData, short Address, short mylen, string HKey, string LKey, string KeyPath);
//***从加密锁中读取一个字节数据,一般不使用
//int YRead(ref byte OutData, short Address,string HKey, string LKey, string KeyPath);
//***写一批字节到加密锁中
//int YWriteEx(byte[] InData, short Address, short mylen, string HKey, string LKey, string KeyPath);
//***写一个字节的数据到加密锁中,一般不使用
//int YWrite(byte InData, short Address, string HKey, string LKey, string KeyPath);
//***从加密锁中读字符串
//int YReadString(ref string outstring, short Address, short mylen, string HKey, string LKey, string KeyPath);
//***写字符串到加密锁中
//int YWriteString(string InString, short Address, string HKey, string LKey, string KeyPath);
//***算法函数
//int sWriteEx(int in_data , ref int out_data , string KeyPath);
//int sWrite_2Ex(int in_data , ref int out_data ,string KeyPath);
//int sRead(ref int in_data, string KeyPath);
//int sWrite(int out_data, string KeyPath);
//int sWrite_2(int out_data, string KeyPath);
//***设置写密码
//int SetWritePassword(string W_HKey, string W_LKey, string new_HKey, string new_LKey, string KeyPath);
//***设置读密码
//int SetReadPassword(string W_HKey, string W_LKey, string new_HKey, string new_LKey, string KeyPath);
//'设置增强算法密钥一
//int SetCal_2(string Key , string KeyPath);
//使用增强算法一对字符串进行加密
//int EncString(string InString , ref string outstring , string KeyPath);
//使用增强算法一对二进制数据进行加密
// int Cal(byte[] InBuf, byte[] OutBuf, string KeyPath);
//'设置增强算法密钥二
//int SetCal_New(string Key , string KeyPath);
//使用增强算法二对字符串进行加密
//int EncString_New(string InString , ref string outstring , string KeyPath);
//使用增强算法二对二进制数据进行加密
// int Cal_New(byte[] InBuf, byte[] OutBuf, string KeyPath);
//***初始化加密锁函数
//int ReSet( string Path);
//***获取字符串长度
//int lstrlenA(string InString );
public void EnCode(byte[] inb, byte[] outb, string Key)//TEA算法加密 程序:增强算法
{
UInt32 cnDelta, y, z, a, b, c, d, temp_2;
UInt32[] buf = new UInt32;
int n, i, nlen;
UInt32 sum;
//UInt32 temp, temp_1;
string temp_string;
cnDelta = 2654435769;
sum = 0;
nlen = Key.Length;
i = 0;
for (n = 1; n <= nlen; n = n + 2)
{
temp_string = Key.Substring(n - 1, 2);
buf = HexToInt(temp_string);
i = i + 1;
}
a = 0; b = 0; c = 0; d = 0;
for (n = 0; n <= 3; n++)
{
a = (buf << (n * 8)) | a;
b = (buf << (n * 8)) | b;
c = (buf << (n * 8)) | c;
d = (buf << (n * 8)) | d;
}
y = 0;
z = 0;
for (n = 0; n <= 3; n++)
{
temp_2 = inb;
y = (temp_2 << (n * 8)) | y;
temp_2 = inb;
z = (temp_2 << (n * 8)) | z;
}
n = 32;
while (n > 0)
{
sum = cnDelta + sum;
/*temp = (z << 4) & 0xFFFFFFFF;
temp = (temp + a) & 0xFFFFFFFF;
temp_1 = (z + sum) & 0xFFFFFFFF;
temp = (temp ^ temp_1) & 0xFFFFFFFF;
temp_1 = (z >> 5) & 0xFFFFFFFF;
temp_1 = (temp_1 + b) & 0xFFFFFFFF;
temp = (temp ^ temp_1) & 0xFFFFFFFF;
temp = (temp + y) & 0xFFFFFFFF;
y = temp & 0xFFFFFFFF;*/
y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
/*temp = (y << 4) & 0xFFFFFFFF;
temp = (temp + c) & 0xFFFFFFFF;
temp_1 = (y + sum) & 0xFFFFFFFF;
temp = (temp ^ temp_1) & 0xFFFFFFFF;
temp_1 = (y >> 5) & 0xFFFFFFFF;
temp_1 = (temp_1 + d) & 0xFFFFFFFF;
temp = (temp ^ temp_1) & 0xFFFFFFFF;
temp = (z + temp) & 0xFFFFFFFF;
z = temp & 0xFFFFFFFF;*/
z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
n = n - 1;
}
for (n = 0; n <= 3; n++)
{
outb = System.Convert.ToByte((y >> (n * 8)) & 255);
outb = System.Convert.ToByte((z >> (n * 8)) & 255);
}
}
public void DeCode(byte[] inb, byte[] outb, string Key)//TEA算法解密 程序:增强算法
{
UInt32 cnDelta, y, z, a, b, c, d, temp_2;
UInt32[] buf = new UInt32;
int n, i, nlen;
UInt32 sum;
//UInt32 temp, temp_1;
string temp_string;
cnDelta = 2654435769;
sum = 0xC6EF3720;
nlen = Key.Length;
i = 0;
for (n = 1; n <= nlen; n = n + 2)
{
temp_string = Key.Substring(n - 1, 2);
buf = HexToInt(temp_string);
i = i + 1;
}
a = 0; b = 0; c = 0; d = 0;
for (n = 0; n <= 3; n++)
{
a = (buf << (n * 8)) | a;
b = (buf << (n * 8)) | b;
c = (buf << (n * 8)) | c;
d = (buf << (n * 8)) | d;
}
y = 0;
z = 0;
for (n = 0; n <= 3; n++)
{
temp_2 = inb;
y = (temp_2 << (n * 8)) | y;
temp_2 = inb;
z = (temp_2 << (n * 8)) | z;
}
n = 32;
while (n-- > 0)
{
z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
sum -= cnDelta;
}
for (n = 0; n <= 3; n++)
{
outb = System.Convert.ToByte((y >> (n * 8)) & 255);
outb = System.Convert.ToByte((z >> (n * 8)) & 255);
}
}
public string StrEnc(string InString, string Key)//使用增强算法,加密字符串 通过程序直接加密,不通过狗
{
byte[] b, outb;
byte[] temp = new byte, outtemp = new byte;
int n, i, nlen, outlen;
string outstring;
nlen = lstrlenA(InString) + 1;
if (nlen < 8)
outlen = 8;
else
outlen = nlen;
b = new byte;
outb = new byte;
CopyStringToByte(b, InString, nlen);
b.CopyTo(outb, 0);
for (n = 0; n <= outlen - 8; n = n + 8)
{
for (i = 0; i < 8; i++) temp = b;
EnCode(temp, outtemp, Key);//TEA算法加密
for (i = 0; i < 8; i++) outb = outtemp;
}
outstring = "";
for (n = 0; n <= outlen - 1; n++)
{
outstring = outstring + outb.ToString("X2");
}
return outstring;
}
public string StrDec(string InString, string Key) //使用增强算法,解密字符串 通过程序直接解密,不通过狗
{
byte[] b, outb;
byte[] temp = new byte, outtemp = new byte;
int n, i, nlen, outlen;
string temp_string;
StringBuilder c_str;
nlen = InString.Length;
if (nlen < 16) outlen = 16;
outlen = nlen / 2;
b = new byte;
outb = new byte;
i = 0;
for (n = 1; n <= nlen; n = n + 2)
{
temp_string = InString.Substring(n - 1, 2);
b = System.Convert.ToByte(HexToInt(temp_string));
i = i + 1;
}
b.CopyTo(outb, 0);
for (n = 0; n <= outlen - 8; n = n + 8)
{
for (i = 0; i < 8; i++) temp = b;
DeCode(temp, outtemp, Key);//TEA算法解密
for (i = 0; i < 8; i++) outb = outtemp;
}
c_str = new StringBuilder("", outlen);
CopyByteToString(c_str, outb, outlen);
return c_str.ToString();
}
详细源代码见附件!
YT88 官方下载 http://www.dgyzt.com/share_show.php?id=96
如果知道 明文 密文 可以根据TEA算法来推算出正确的 TEA算法密钥 吗?
觉得好的请+热心, +吾爱币
fghtiger 发表于 2015-12-27 10:55
下点官方手册,就能破了吗。
不是的,还得看软件作者怎么验证! 不知道算法密钥 是不能复制一模一样的狗的,但是可以根据程序验证狗的代码 提供符合条件的数据或者自己重新 写空狗来满足程序简单的验证 13407720031 发表于 2016-4-26 20:43
问下这个代码该怎么使用呢?小白一个请赐教。
提供加密解密的函数,只要有密钥就能加解密 感谢. 先留着备份,加密狗很久没玩过了 也许用的上. 感谢分享 下点官方手册,就能破了吗。 感谢分享...学习一下... Sound 发表于 2015-12-27 05:15
感谢. 先留着备份,加密狗很久没玩过了 也许用的上.
大神 啊 大神啊 大神啊 大神啊 大神啊 问下这个代码该怎么使用呢?小白一个请赐教。 感谢楼主分享这么好的内容,谢谢!
页:
[1]
2