⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc5.h

📁 根据rc5的c算法修改
💻 H
字号:
/* rc5.h */

#ifndef RC5_H
#define RC5_H

#include <afx.h>

//typedef byte[] UPCHAR;
//typedef unsigned long int LWORD; /* Should be 32-bit = 4 bytes        */
#define ws        32             /* word size in bits                 */
#define rn        12             /* number of rounds                  */  
#define bn        16             /* number of bytes in key            */
#define cn         4             /* number  words in key = ceil(8*b/w)*/
#define ts        26             /* size of table S = 2*(r+1) words   */

/* Rotation operators. x must be unsigned, to get logical right shift*/
//#define ROTL(x,y) (((x)<<(y&(ws-1))) | ((x)>>(ws-(y&(ws-1)))))
//#define ROTR(x,y) (((x)>>(y&(ws-1))) | ((x)<<(ws-(y&(ws-1)))))

void ROTL(x,y)
{
	(((x)<<(y&(ws-1))) | ((x)>>(ws-(y&(ws-1)))));
}
void ROTR(x,y)
{
	(((x)>>(y&(ws-1))) | ((x)<<(ws-(y&(ws-1)))));
}
class CRC5
{
public: 
	void HexToBin(LPSTR hex, LPSTR buf, int bufSize);
	void BinToHex(LPSTR buf, LPSTR hex, int bufSize);
	CString Encrypt(CString str);
	CString Decrypt(CString str);
	CRC5();

/* set key for rc5 to encrypt and decrypt
   K is the init key*/
	void Setup(unsigned char *K);

/* rc5 to encrypt 
   ibuf is the char will be encrypted 
   obuf is the char have encrypted 
   len is the lenth of char will be encrypted*/	
	unsigned long Encrypt(unsigned char * ibuf, unsigned char * obuf, unsigned long len);

/* rc5 to decrypt
   ibuf is the char will be decrypted
   obuf is the char have decrypted
   len is the lenth of char will be decrypted*/
	unsigned long Decrypt(unsigned char * ibuf,unsigned char * obuf,unsigned long len);
	
private:
	LWORD S[ts];                      /* expanded key table                */

	void ENCRYPT(LWORD *pt, LWORD *ct);
	//Do Encrypt 2 WORD input pt/output ct 

	void DECRYPT(LWORD *ct, LWORD *pt); 
	//Do Decrypt2 WORD input ct/output pt    
	
	void SETUP(unsigned char *K); 
	//secret input key K[0...b-1]      
    
	unsigned char CharToLong(unsigned char *ch,unsigned long *lg);
	//change the miwen stored in char to longch is type of unsigned char ,lg is type of unsigned long
	
	unsigned char LongToChar(unsigned long *lg,unsigned char *ch);
	//change the miwen stored in long to  charlg store unsigned long,ch store unsigned char	
};


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -