Exemplo n.º 1
0
//rc6
BOOL CEncrypt::Rc6Encrypt(const char* szInDataBuff, uint32_t nInDataSize, 
	char* szOutDataBuff, uint32_t& nOutDataSize)
{
	assert(m_stRc6Ctx.l_key[0] != 0);
	assert(nOutDataSize >= ((nInDataSize + 15) / 16) * 16);

	nOutDataSize = 0;
	int nDataLen = nInDataSize - nInDataSize % 16;
	while (nOutDataSize < nDataLen)
	{
		rc6_encrypt((const unsigned long *)(szInDataBuff + nOutDataSize),
			(unsigned long *)(szOutDataBuff + nOutDataSize),&m_stRc6Ctx);
		nOutDataSize += 16;
	}

	if (nDataLen < nInDataSize)
	{
		unsigned long  llInBuff[4] = {0};
		memcpy(llInBuff,szInDataBuff + nOutDataSize,nInDataSize % 16);
		rc6_encrypt((const unsigned long *)llInBuff,
			(unsigned long *)(szOutDataBuff + nOutDataSize),&m_stRc6Ctx);
		nOutDataSize += 16;
	}
	return TRUE;
}
Exemplo n.º 2
0
int main()                          //Driving function
{
	char type[20],tmp[20];
    	unsigned int pt1[32],k;
    	int keylen,i;
	unsigned char key[64],d1;
	FILE *fp=fopen("input.txt","r");
        fscanf(fp,"%s",type);
        fscanf(fp,"%s",tmp);
 	for(i=0;i<16;i++)
	{
	         fscanf(fp,"%x",&k);
		 pt[i]=k;
        }
         fscanf(fp,"%s",tmp);
                      
         i=0;      
         for(i=0;!feof(fp);i++)
         {
                 fscanf(fp,"%x",&k);
                 key[i]=k;
         }
	 keylen=i-1;
	 rc6_key(key, keylen);
	 pt1[3]=0;
 	 int b=16;
	 for(i=b-1;i>=0;i--)
	 {
		pt1[i/bytes]=(pt1[i/bytes]<<8)+pt[i];
 	 }
	if(strstr(type,"Encryption"))
		rc6_encrypt(pt1);
	else
		rc6_decrypt(pt1);
        return 0;
}