- 博客(0)
- 资源 (3)
- 收藏
- 关注
C#实现TEA算法
用C#实现的TEA算法,测试可用
public static byte[] Encrypt(byte[] data, byte[] key)
{
byte[] dataBytes;
if (data.Length % 2 == 0)
{
dataBytes = data;
}
else
{
dataBytes = new byte[data.Length + 1];
Array.Copy(data, 0, dataBytes, 0, data.Length);
dataBytes[data.Length] = 0x0;
}
byte[] result = new byte[dataBytes.Length * 4];
uint[] formattedKey = FormatKey(key);
uint[] tempData = new uint[2];
for (int i = 0; i < dataBytes.Length; i += 2)
{
tempData[0] = dataBytes[i];
tempData[1] = dataBytes[i + 1];
code(tempData, formattedKey);
Array.Copy(ConvertUIntToByteArray(tempData[0]), 0, result, i * 4, 4);
Array.Copy(ConvertUIntToByteArray(tempData[1]), 0, result, i * 4 + 4, 4);
}
return result;
}
2015-09-01
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人