Keeloq 编解码测试
来源:互联网 发布:爱丽小屋淘宝旗舰店 编辑:程序博客网 时间:2024/05/05 20:08
参考资料:
http://en.wikipedia.org/wiki/KeeLoq
http://cryptolib.com/ciphers/keeloq/
测试程序:
#include <stdio.h>
#include <stdlib.h>typedef unsigned long u32;
typedef unsigned long long u64;
/*\
* Corrected KeeLoq Encryption and Decryption functions by Ruptor.
* Use at your own risk! This source is not copyrighted.
* Encoder encrypts an all-0 block, decoder decrypts it.
* KeeLoq cipher encrypts 32-bit blocks with 64-bit keys.
* Key is XORed with a 32-bit IV incremented on each use.
* See http://www.keeloq.boom.ru/decryption.pdf for more details.
* KeeLoq algorithm itself is not patented.
\*/
#define KeeLoq_NLF 0x3A5C742E
#define bit(x,n) (((x)>>(n))&1)
#define g5(x,a,b,c,d,e) (bit(x,a)+bit(x,b)*2+bit(x,c)*4+bit(x,d)*8+bit(x,e)*16)
u32 KeeLoq_Encrypt (const u32 data, const u64 key)
{
u32 x = data, r,u1,u2,u3,u4,u5,u0;
for (r = 0; r < 528; r++)
{
x = (x>>1)^((bit(x,0)^bit(x,16)^(u32)bit(key,r&63)^bit(KeeLoq_NLF,g5(x,1,9,20,26,31)))<<31);
}
printf("Encrypt in:%08x,out:%08x\n",data,x);
return x;
}
u32 KeeLoq_Decrypt (const u32 data, const u64 key)
{
u32 x = data, r;
for (r = 0; r < 528; r++)
{
x = (x<<1)^bit(x,31)^bit(x,15)^(u32)bit(key,(15-r)&63)^bit(KeeLoq_NLF,g5(x,0,8,19,25,30));
}
printf("Decrypt in:%08x,out:%08x\n",data,x);
return x;
}
int main(int argc, char *argv[])
{
u32 data = 0x76543210;
u64 key = 0x0123456789abcdef;
u32 dataEc;
u32 dataDc;
dataEc = KeeLoq_Encrypt(data,key);
dataDc = KeeLoq_Decrypt(dataEc,key);
system("PAUSE");
return EXIT_SUCCESS;
}
- Keeloq 编解码测试
- Keeloq解码软件实现
- dm8148 jpeg编解码测试
- 机顶盒编解码视频质量测试方法
- 编解码
- HTC Hero内置播放器的视频编解码测试
- QuaZip源码编译及其编解码功能的测试
- GPU视频编解码及性能质量测试基础
- MessagePack编解码功能测试代码补齐
- android语音编解码:speex编解码
- url编解码与base64编解码
- 硬件编解码&软件编解码
- 视频质量测试常见编解码表,各种视频测试知识列表
- 十六进制编解码
- h264视频编解码
- UUENCODE编解码
- AMR音频编解码
- VB Base64编解码
- HTML5 拖拽图片到网页内
- SqlDependency based caching of LINQ Queries
- NYOJ 249 最大长方形
- Android 检测是否有ROOT权限
- iPhone开发 虚拟器程序安装及键盘语言设置
- Keeloq 编解码测试
- Core Dump解析
- linux解压 tar命令
- Jenkins的授权和访问控制
- 修改mac os分辨率(VMware)
- 如何解压cpio.gz文件?
- WPF WebBrowser 使用window.open()打开 新窗口相关问题的解决
- 多态 覆盖 重载 重写 模板 泛型
- Yii验证与授权