C#实现TEA算法

时间:2018-09-21 08:25:57
【文件属性】:
文件名称:C#实现TEA算法
文件大小:5KB
文件格式:CS
更新时间:2018-09-21 08:25:57
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; }

网友评论