int main(int argc, char*argv[]) { word32 dat[2], enc[2], dec[2], *ky; int i; unsigned char key[] = { 0x91, 0x5f, 0x46, 0x19, 0xbe, 0x41, 0xb2, 0x51, 0x63, 0x55, 0xa5, 0x01, 0x10, 0xa9, 0xce, 0x91}; *dat = 0xEEDBA521; *(dat+1) = 0x6D8F4B15; rounds = atoi(argv[1]); /* printf("Enter Rounds: "); scanf("%d", &rounds); */ t = KR(rounds); fprintf( stderr,"t = %d\nrounds = %d\n",t, rounds ); ky = (word32 *) calloc(t, sizeof(word32)); RC5key(key, sizeof(key), ky); RC5encrypt(dat, enc, ky); RC5decrypt(enc, dec, ky); printf("Dat: %x %x\n", dat[0], dat[1]); printf("Enc: %x %x\n", enc[0], enc[1]); printf("Dec: %x %x\n", dec[0], dec[1]); return 0; } /* End */
void RC5decrypt(word32 const *in, word32 *out, word32 *key) { register word32 a, b; int i; a = *in; b = *(in+1); key += KR(rounds); //fprintf(stderr,"a=%X, b=%X\n",a,b); for (i = 0; i < rounds; i++) { b -= *--key; //fprintf(stderr, "b_res = %X\n", b); b = ROTR(b, a&ANDVAL) ^ a; //fprintf(stderr, "b_rot = %X\n", b); //b = b ^ a; //fprintf(stderr, "b_xor = %X\n\n", b); a -= *--key; fprintf(stderr, "a_res = %X\n", a); a = ROTR(a, b&ANDVAL) ^ b; fprintf(stderr, "a_rot = %X\n\n", a); //fprintf(stderr,"a=%X, b=%X\n",a,b); } b -= *--key; a -= *--key; *out = a; *(out+1) = b; }
//--------------------------------------------decomposeProhMats-------------------------------------------// // through the projection matrix we can get nearly all the information of the cameras // the position of the camera // the direction of the camera // the focal of the camera // the axises of the camera void Camera::decomposeProjMats() { // 1.0 get direction this->dir_.at<float>(0) = this->project_.at<float>(2,0); this->dir_.at<float>(1) = this->project_.at<float>(2,1); this->dir_.at<float>(2) = this->project_.at<float>(2,2); this->dir_ = this->dir_/ norm(this->dir_); // 2.0 get position cv::Mat KR(3,3,CV_32FC1); cv::Mat KT(3,1,CV_32FC1); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { KR.at<float>(i,j) = this->project_.at<float>(i,j); } } for(int i=0; i<3; i++) KT.at<float>(i,0) = this->project_.at<float>(i,3); this->pos_ = -KR.inv()* KT; // 3.0 compute the focal cv::Mat R0(3,1, CV_32FC1); cv::Mat R1(3, 1, CV_32FC1); cv::Mat R2(3, 1, CV_32FC1); for(int i=0; i<3; i++) { R0.at<float>(i) = KR.at<float>(0, i); R1.at<float>(i) = KR.at<float>(1, i); R2.at<float>(i) = KR.at<float>(2, i); } this->focal_ = 0.5*abs(norm(R0.cross(R2)))+ 0.5*abs(norm(R1.cross(R2))); // 4.0 axises of the camera this->zaxis_ = this->dir_; this->yaxis_ = this->zaxis_.cross(R0); this->yaxis_ = this->yaxis_/norm(this->yaxis_); this->xaxis_ = this->yaxis_.cross(this->zaxis_); this->xaxis_ = this->xaxis_/norm(this->xaxis_); KR.release(); KT.release(); R0.release(); R1.release(); R2.release(); }