资源简介
3DES,C语言版,ECB,PKCS7,windows,linux通用,编译通过实测,base64输出,可以与在线网站对比
代码片段和文件信息
#include
#include
#include
#define DES_LONG unsigned long
#define LEN_OF_KEY 24
#define ITERATIONS 16
#define c2l(cl) (l =((DES_LONG)(*((c)++))) \
l|=((DES_LONG)(*((c)++)))<< 8L \
l|=((DES_LONG)(*((c)++)))<<16L \
l|=((DES_LONG)(*((c)++)))<<24L)
#define l2c(lc) (*((c)++)=(unsigned char)(((l) )&0xff) \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff) \
*((c)++)=(unsigned char)(((l)>>16L)&0xff) \
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
#define ROTATE(an) (((a)>>(n))+((a)<<(32-(n))))
#define LOAD_DATA_tmp(abcdef) LOAD_DATA(abcdefg)
#define LOAD_DATA(RSutE0E1tmp) \
u=R^s[S ]; \
t=R^s[S+1]
#define D_ENCRYPT(LLRS) {\
LOAD_DATA_tmp(RSutE0E1); \
t=ROTATE(t4); \
LL^=\
DES_SPtrans[0][(u>> 2L)&0x3f]^ \
DES_SPtrans[2][(u>>10L)&0x3f]^ \
DES_SPtrans[4][(u>>18L)&0x3f]^ \
DES_SPtrans[6][(u>>26L)&0x3f]^ \
DES_SPtrans[1][(t>> 2L)&0x3f]^ \
DES_SPtrans[3][(t>>10L)&0x3f]^ \
DES_SPtrans[5][(t>>18L)&0x3f]^ \
DES_SPtrans[7][(t>>26L)&0x3f]; }
#define PERM_OP(abtnm) ((t)=((((a)>>(n))^(b))&(m))\
(b)^=(t)\
(a)^=((t)<<(n)))
#define IP(lr) \
{ \
register DES_LONG tt; \
PERM_OP(rltt 40x0f0f0f0fL); \
PERM_OP(lrtt160x0000ffffL); \
PERM_OP(rltt 20x33333333L); \
PERM_OP(lrtt 80x00ff00ffL); \
PERM_OP(rltt 10x55555555L); \
}
#define FP(lr) \
{ \
register DES_LONG tt; \
PERM_OP(lrtt 10x55555555L); \
PERM_OP(rltt 80x00ff00ffL); \
PERM_OP(lrtt 20x33333333L); \
PERM_OP(rltt160x0000ffffL); \
PERM_OP(lrtt 40x0f0f0f0fL); \
}
extern const DES_LONG DES_SPtrans[8][64];
#define HPERM_OP(atnm) ((t)=((((a)<<(16-(n)))^(a))&(m))\
(a)=(a)^(t)^(t>>(16-(n))))
static const DES_LONG des_skb[8][64] = {
{
/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
0x00000000L 0x00000010L 0x20000000L 0x20000010L
0x00010000L 0x00010010L 0x20010000L 0x20010010L
0x00000800L 0x00000810L 0x20000800L 0x20000810L
0x00010800L 0x00010810L 0x20010800L 0x20010810L
0x00000020L 0x00000030L 0x20000020L 0x20000030L
0x00010020L 0x00010030L 0x20010020L 0x20010030L
0x00000820L 0x00000830L 0x20000820L 0x20000830L
0x00010820L 0x00010830L 0x20010820L 0x20010830L
0x00080000L 0x00080010L 0x20080000L 0x20080010L
0x00090000L 0x00090010L 0x20090000L 0x20090010L
0x00080800L 0x00080810L 0x20080800L 0x20080810L
0x00090800L 0x00090810L 0x20090800L 0x20090810L
0x00080020
评论
共有 条评论