资源简介
在基于vc.net基础上,采用经典的rc5 方法对文件加解密
欢迎批评
此算法已经调试通过

代码片段和文件信息
/* RC5REF.C -- Reference implementation of RC5-32/12/16 in C. */
/* Copyright (C) 1995 RSA Data Security Inc. */
#include
#include
typedef unsigned long int WORD; /* Should be 32-bit = 4 bytes */
#define w 32 /* word size in bits */
#define r 12 /* number of rounds */
#define b 16 /* number of bytes in key */
#define c 4 /* number words in key = ceil(8*b/w)*/
#define t 26 /* size of table S = 2*(r+1) words */
WORD S[t]; /* expanded key table */
WORD P = 0xb7e15163 Q = 0x9e3779b9; /* magic constants */
/* Rotation operators. x must be unsigned to get logical right shift*/
#define ROTL(xy) (((x)<<(y&(w-1))) | ((x)>>(w-(y&(w-1)))))
#define ROTR(xy) (((x)>>(y&(w-1))) | ((x)<<(w-(y&(w-1)))))
void RC5_ENCRYPT(WORD *pt WORD *ct) /* 2 WORD input pt/output ct */
{ WORD i A=pt[0]+S[0] B=pt[1]+S[1];
for (i=1; i<=r; i++)
{ A = ROTL(A^BB)+S[2*i];
B = ROTL(B^AA)+S[2*i+1];
}
ct[0] = A; ct[1] = B;
}
void RC5_DECRYPT(WORD *ct WORD *pt) /* 2 WORD input ct/output pt */
{ WORD i B=ct[1] A=ct[0];
for (i=r; i>0; i--)
{ B = ROTR(B-S[2*i+1]A)^A;
A = ROTR(A-S[2*i]B)^B;
}
pt[1] = B-S[1]; pt[0] = A-S[0];
}
void RC5_SETUP(unsigned char *K) /* secret input key K[0...b-1] */
{ WORD i j k u=w/8 A B L[c];
/* Initialize L then S then mix key into S */
for (i=b-1L[c-1]=0; i!=-1; i--) L[i/u] = (L[i/u]<<8)+K[i];
for (S[0]=Pi=1; i for (A=B=i=j=k=0; k<3*t; k++i=(i+1)%tj=(j+1)%c) /* 3*t > 3*c */
{ A = S[i] = ROTL(S[i]+(A+B)3);
B = L[j] = ROTL(L[j]+(A+B)(A+B));
}
}
void main()
{ WORD i j pt1[2] pt2[2] ct[2] = {00};
unsigned char key[b];
time_t t0 t1;
if (sizeof(WORD)!=4)
printf(“RC5 error: WORD has %d bytes.\n“sizeof(WORD));
printf(“RC5-32/12/16 examples:\n“);
for (i=1;i<6;i++)
{ /* Initialize pt1 and key pseudorandomly based on previous ct */
pt1[0]=ct[0]; pt1[1]=ct[1];
for (j=0;j /* Setup encrypt and decrypt */
RC5_SETUP(key);
RC5_ENCRYPT(pt1ct);
RC5_DECRYPT(ctpt2);
/* Print out results checking for decryption failure */
printf(“\n%d. key = “i);
for (j=0; j printf(“\n plaintext %.8lX %.8lX ---> ciphertext %.8lX %.8lX \n“
pt1[0] pt1[1] ct[0] ct[1]);
if (pt1[0]!=pt2[0] || pt1[1]!=pt2[1])
printf(“Decryption Error!“);
}
time (&t0);
for (i=1;i<100000;i++)
RC5_ENCRYPT(ctct);
time (&t1);
printf (“\n Time_t for 100000 blocks: %ld \n“ t1-t0);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5963 1999-09-02 12:49 rc5-info-from-rsa.txt
文件 31896 1999-09-02 12:50 rc5.ps.gz
文件 7089 1999-09-02 12:50 rc5.tex.gz
文件 2862 1999-09-02 12:50 rc5ref.c
文件 697 1999-09-02 12:50 rc5ref.out
相关资源
- 3des加解密_C 实现
- 易语言RSA加解密源码
- Delphi 版 SM3 SM4加解密
- 密码学实验RSA加解密
- delphi下用Lockbox中rsa进行加解密的范例
- AES加解密工具支持16进制.zip
- AES加解密算法的FPGA优化设计
- AES加解密aes128/192/256 ecb cbc cfb ofb ctr
- xxtea加解密工具win32
- 信息安全实验:利用Windows CryptoAPI开发
- AES加解密算法软件程序包含全部模式
- openssl绿色版
- 基于GMSSL的SM9签名,密钥交换,加密,
- 易语言 异或封包加解密助手1.2 模块
- SFCipher加解密工具
- 导入文件方式实现8、16、24字节秘钥的
- 信息安全实验:利用Windows CryptoAPI开发
- 16字节加解密的AES算法.zip
- AES加解密-CBC模式-文件操作
- sm2 sm9 加密 解密 签名 验签工具
- RSA加解密生成DLL调用
- 安全的即时通信软件.zip
- iOS demo SM2,SM4 加密算法,SM2+SM3签名
- 基于minifilter的分布式驱动级文件透明
- ASE和RSA加解密
- CryptoAPI加解密签名验证
- 微信公众号开发消息加解密工具类
- 基于API_HOOK的数据文件透明加解密系统
- PKCS#7格式加解密验签
- OPENSSL AES 加解密例程
评论
共有 条评论