├── AES.cpp ├── AES.h ├── README └── Test.cpp /AES.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | 4 | 5 | #include "AES.h" 6 | #include 7 | #include 8 | #include 9 | 10 | AES::AES(unsigned char* key) 11 | { 12 | unsigned char sBox[] = 13 | { /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ 14 | 0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76, /*0*/ 15 | 0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0, /*1*/ 16 | 0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15, /*2*/ 17 | 0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75, /*3*/ 18 | 0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84, /*4*/ 19 | 0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf, /*5*/ 20 | 0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8, /*6*/ 21 | 0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2, /*7*/ 22 | 0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73, /*8*/ 23 | 0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb, /*9*/ 24 | 0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79, /*a*/ 25 | 0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08, /*b*/ 26 | 0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a, /*c*/ 27 | 0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e, /*d*/ 28 | 0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf, /*e*/ 29 | 0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16 /*f*/ 30 | }; 31 | unsigned char invsBox[256] = 32 | { /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ 33 | 0x52,0x09,0x6a,0xd5,0x30,0x36,0xa5,0x38,0xbf,0x40,0xa3,0x9e,0x81,0xf3,0xd7,0xfb, /*0*/ 34 | 0x7c,0xe3,0x39,0x82,0x9b,0x2f,0xff,0x87,0x34,0x8e,0x43,0x44,0xc4,0xde,0xe9,0xcb, /*1*/ 35 | 0x54,0x7b,0x94,0x32,0xa6,0xc2,0x23,0x3d,0xee,0x4c,0x95,0x0b,0x42,0xfa,0xc3,0x4e, /*2*/ 36 | 0x08,0x2e,0xa1,0x66,0x28,0xd9,0x24,0xb2,0x76,0x5b,0xa2,0x49,0x6d,0x8b,0xd1,0x25, /*3*/ 37 | 0x72,0xf8,0xf6,0x64,0x86,0x68,0x98,0x16,0xd4,0xa4,0x5c,0xcc,0x5d,0x65,0xb6,0x92, /*4*/ 38 | 0x6c,0x70,0x48,0x50,0xfd,0xed,0xb9,0xda,0x5e,0x15,0x46,0x57,0xa7,0x8d,0x9d,0x84, /*5*/ 39 | 0x90,0xd8,0xab,0x00,0x8c,0xbc,0xd3,0x0a,0xf7,0xe4,0x58,0x05,0xb8,0xb3,0x45,0x06, /*6*/ 40 | 0xd0,0x2c,0x1e,0x8f,0xca,0x3f,0x0f,0x02,0xc1,0xaf,0xbd,0x03,0x01,0x13,0x8a,0x6b, /*7*/ 41 | 0x3a,0x91,0x11,0x41,0x4f,0x67,0xdc,0xea,0x97,0xf2,0xcf,0xce,0xf0,0xb4,0xe6,0x73, /*8*/ 42 | 0x96,0xac,0x74,0x22,0xe7,0xad,0x35,0x85,0xe2,0xf9,0x37,0xe8,0x1c,0x75,0xdf,0x6e, /*9*/ 43 | 0x47,0xf1,0x1a,0x71,0x1d,0x29,0xc5,0x89,0x6f,0xb7,0x62,0x0e,0xaa,0x18,0xbe,0x1b, /*a*/ 44 | 0xfc,0x56,0x3e,0x4b,0xc6,0xd2,0x79,0x20,0x9a,0xdb,0xc0,0xfe,0x78,0xcd,0x5a,0xf4, /*b*/ 45 | 0x1f,0xdd,0xa8,0x33,0x88,0x07,0xc7,0x31,0xb1,0x12,0x10,0x59,0x27,0x80,0xec,0x5f, /*c*/ 46 | 0x60,0x51,0x7f,0xa9,0x19,0xb5,0x4a,0x0d,0x2d,0xe5,0x7a,0x9f,0x93,0xc9,0x9c,0xef, /*d*/ 47 | 0xa0,0xe0,0x3b,0x4d,0xae,0x2a,0xf5,0xb0,0xc8,0xeb,0xbb,0x3c,0x83,0x53,0x99,0x61, /*e*/ 48 | 0x17,0x2b,0x04,0x7e,0xba,0x77,0xd6,0x26,0xe1,0x69,0x14,0x63,0x55,0x21,0x0c,0x7d /*f*/ 49 | }; 50 | memcpy(Sbox, sBox, 256); 51 | memcpy(InvSbox, invsBox, 256); 52 | if (key != NULL) { 53 | KeyExpansion(key, w); 54 | } 55 | } 56 | 57 | AES::~AES() 58 | { 59 | 60 | } 61 | 62 | void AES::SetKey (unsigned char *key) { 63 | KeyExpansion(key, w); 64 | } 65 | 66 | unsigned char* AES::Cipher(unsigned char* input, unsigned char *output) 67 | { 68 | unsigned char state[4][4]; 69 | int i,r,c; 70 | 71 | for(r=0; r<4; r++) 72 | { 73 | for(c=0; c<4 ;c++) 74 | { 75 | state[r][c] = input[c*4+r]; 76 | } 77 | } 78 | 79 | AddRoundKey(state,w[0]); 80 | 81 | for(i=1; i<=10; i++) 82 | { 83 | SubBytes(state); 84 | ShiftRows(state); 85 | if(i!=10)MixColumns(state); 86 | AddRoundKey(state,w[i]); 87 | } 88 | 89 | for(r=0; r<4; r++) 90 | { 91 | for(c=0; c<4 ;c++) 92 | { 93 | output[c*4+r] = state[r][c]; 94 | } 95 | } 96 | 97 | return output; 98 | } 99 | 100 | unsigned char* AES::InvCipher(unsigned char* input, unsigned char *output) 101 | { 102 | unsigned char state[4][4]; 103 | int i,r,c; 104 | 105 | for(r=0; r<4; r++) 106 | { 107 | for(c=0; c<4 ;c++) 108 | { 109 | state[r][c] = input[c*4+r]; 110 | } 111 | } 112 | 113 | AddRoundKey(state, w[10]); 114 | for(i=9; i>=0; i--) 115 | { 116 | InvShiftRows(state); 117 | InvSubBytes(state); 118 | AddRoundKey(state, w[i]); 119 | if(i) 120 | { 121 | InvMixColumns(state); 122 | } 123 | } 124 | 125 | for(r=0; r<4; r++) 126 | { 127 | for(c=0; c<4 ;c++) 128 | { 129 | output[c*4+r] = state[r][c]; 130 | } 131 | } 132 | return output; 133 | } 134 | 135 | void* AES::Cipher(void* input, void *output, int length) 136 | { 137 | unsigned char* in = (unsigned char*) input; 138 | unsigned char* out = (unsigned char*) output; 139 | int i; 140 | if(!length) 141 | { 142 | while(*(in+length++)); 143 | in = (unsigned char*) input; 144 | } 145 | for(i=0; i>i)&0x01) 219 | { 220 | res ^= bw[i]; 221 | } 222 | } 223 | return res; 224 | } 225 | 226 | void AES::SubBytes(unsigned char state[][4]) 227 | { 228 | int r,c; 229 | for(r=0; r<4; r++) 230 | { 231 | for(c=0; c<4; c++) 232 | { 233 | state[r][c] = Sbox[state[r][c]]; 234 | } 235 | } 236 | } 237 | 238 | void AES::ShiftRows(unsigned char state[][4]) 239 | { 240 | unsigned char t[4]; 241 | int r,c; 242 | for(r=1; r<4; r++) 243 | { 244 | for(c=0; c<4; c++) 245 | { 246 | t[c] = state[r][(c+r)%4]; 247 | } 248 | for(c=0; c<4; c++) 249 | { 250 | state[r][c] = t[c]; 251 | } 252 | } 253 | } 254 | 255 | void AES::MixColumns(unsigned char state[][4]) 256 | { 257 | unsigned char t[4]; 258 | int r,c; 259 | for(c=0; c< 4; c++) 260 | { 261 | for(r=0; r<4; r++) 262 | { 263 | t[r] = state[r][c]; 264 | } 265 | for(r=0; r<4; r++) 266 | { 267 | state[r][c] = FFmul(0x02, t[r]) 268 | ^ FFmul(0x03, t[(r+1)%4]) 269 | ^ FFmul(0x01, t[(r+2)%4]) 270 | ^ FFmul(0x01, t[(r+3)%4]); 271 | } 272 | } 273 | } 274 | 275 | void AES::AddRoundKey(unsigned char state[][4], unsigned char k[][4]) 276 | { 277 | int r,c; 278 | for(c=0; c<4; c++) 279 | { 280 | for(r=0; r<4; r++) 281 | { 282 | state[r][c] ^= k[r][c]; 283 | } 284 | } 285 | } 286 | 287 | void AES::InvSubBytes(unsigned char state[][4]) 288 | { 289 | int r,c; 290 | for(r=0; r<4; r++) 291 | { 292 | for(c=0; c<4; c++) 293 | { 294 | state[r][c] = InvSbox[state[r][c]]; 295 | } 296 | } 297 | } 298 | 299 | void AES::InvShiftRows(unsigned char state[][4]) 300 | { 301 | unsigned char t[4]; 302 | int r,c; 303 | for(r=1; r<4; r++) 304 | { 305 | for(c=0; c<4; c++) 306 | { 307 | t[c] = state[r][(c-r+4)%4]; 308 | } 309 | for(c=0; c<4; c++) 310 | { 311 | state[r][c] = t[c]; 312 | } 313 | } 314 | } 315 | 316 | void AES::InvMixColumns(unsigned char state[][4]) 317 | { 318 | unsigned char t[4]; 319 | int r,c; 320 | for(c=0; c< 4; c++) 321 | { 322 | for(r=0; r<4; r++) 323 | { 324 | t[r] = state[r][c]; 325 | } 326 | for(r=0; r<4; r++) 327 | { 328 | state[r][c] = FFmul(0x0e, t[r]) 329 | ^ FFmul(0x0b, t[(r+1)%4]) 330 | ^ FFmul(0x0d, t[(r+2)%4]) 331 | ^ FFmul(0x09, t[(r+3)%4]); 332 | } 333 | } 334 | } 335 | 336 | /**************************************************************/ 337 | //AESModeOfOperation 338 | 339 | AESModeOfOperation::AESModeOfOperation() { 340 | m_mode = MODE_ECB; 341 | m_aes = NULL; 342 | memset(m_key, 0, 16); 343 | memset(m_iv, 0, 16); 344 | m_aes = new AES(m_key); 345 | assert(m_aes != NULL); 346 | } 347 | 348 | AESModeOfOperation::~AESModeOfOperation() { 349 | delete m_aes; 350 | } 351 | 352 | void AESModeOfOperation::set_mode(AESMode_t _mode) { 353 | m_mode = _mode; 354 | } 355 | 356 | void AESModeOfOperation::set_key(unsigned char *_key) { 357 | assert(_key != NULL); 358 | memcpy(m_key, _key, 16); 359 | m_aes->SetKey(m_key); 360 | } 361 | void AESModeOfOperation::set_iv(unsigned char *_iv) { 362 | assert(_iv != NULL); 363 | memcpy(m_iv, _iv, 16); 364 | } 365 | 366 | int AESModeOfOperation::Encrypt(unsigned char *_in, int _length, unsigned char *_out) { 367 | bool first_round = true; 368 | int rounds = 0; 369 | int start = 0; 370 | int end = 0; 371 | unsigned char input[16] = {0}; 372 | unsigned char output[16] = {0}; 373 | unsigned char ciphertext[16] = {0}; 374 | unsigned char cipherout[256] = {0}; 375 | unsigned char plaintext[16] = {0}; 376 | int co_index = 0; 377 | // 1. get rounds 378 | if ( _length % 16 == 0) { 379 | rounds = _length / 16; 380 | } else { 381 | rounds = _length / 16 + 1; 382 | } 383 | // 2. for all rounds 384 | for (int j = 0; j < rounds; ++j) { 385 | start = j*16; 386 | end = j*16 + 16; 387 | if (end > _length) end = _length; // end of input 388 | // 3. copyt input to m_plaintext 389 | memset(plaintext, 0, 16); 390 | memcpy(plaintext, _in + start, end - start); 391 | // 4. handle all modes 392 | if (m_mode == MODE_CFB) { 393 | if (first_round == true) { 394 | m_aes->Cipher(m_iv, output); 395 | first_round = false; 396 | } else { 397 | m_aes->Cipher(input,output); 398 | } 399 | for (int i = 0; i < 16; ++i) { 400 | if ( (end - start) - 1 < i) { 401 | ciphertext[i] = 0 ^ output[i]; 402 | } else { 403 | ciphertext[i] = plaintext[i] ^ output[i]; 404 | } 405 | } 406 | for (int k = 0 ; k < end - start; ++k) { 407 | cipherout[co_index++] = ciphertext[k]; 408 | } 409 | //memset(input,0, 16); 410 | memcpy(input,ciphertext, 16); 411 | } else if (m_mode == MODE_OFB) { // MODE_OFB 412 | if (first_round == true) { 413 | m_aes->Cipher(m_iv,output); // 414 | first_round = false; 415 | } else { 416 | m_aes->Cipher(input, output); 417 | } 418 | // ciphertext = plaintext ^ output 419 | for (int i = 0; i < 16; ++i) { 420 | if ( (end - start) - 1 < i) { 421 | ciphertext[i] = 0 ^ output[i]; 422 | } else { 423 | ciphertext[i] = plaintext[i] ^ output[i]; 424 | } 425 | } 426 | // 427 | for (int k = 0; k < end - start; ++k) { 428 | cipherout[co_index++] = ciphertext[k]; 429 | } 430 | //memset(input,0,16); 431 | memcpy(input, output, 16); 432 | } else if (m_mode == MODE_CBC) { // MODE_CBC 433 | printf("-----plaintext------"); 434 | print(plaintext, 16); 435 | printf("--------------------\n"); 436 | // printf("-----m_iv-----------\n"); 437 | // print (m_iv, 16); 438 | // printf("--------------------\n"); 439 | for (int i = 0; i < 16; ++i) { 440 | if (first_round == true) { 441 | input[i] = plaintext[i] ^ m_iv[i]; 442 | } else { 443 | input[i] = plaintext[i] ^ ciphertext[i]; 444 | } 445 | } 446 | first_round = false; 447 | // printf("^^^^^^^^^^^^\n"); 448 | // print(input, 16); 449 | // printf("^^^^^^^^^^^^\n"); 450 | m_aes->Cipher(input, ciphertext); 451 | printf("****ciphertext****"); 452 | print(ciphertext, 16); 453 | printf("************\n"); 454 | for (int k = 0; k < end - start; ++k){ 455 | cipherout[co_index++] = ciphertext[k]; 456 | } 457 | //memcpy(cipherout, ciphertext, 16); 458 | //co_index = 16; 459 | } else if (m_mode == MODE_ECB) { 460 | // TODO: 461 | } 462 | } 463 | memcpy(_out, cipherout, co_index); 464 | return co_index; 465 | } 466 | 467 | int AESModeOfOperation::Decrypt(unsigned char *_in, int _length, unsigned char *_out) { 468 | // TODO : 469 | bool first_round = true; 470 | int rounds = 0; 471 | unsigned char ciphertext[16] = {0}; 472 | unsigned char input[16] = {0}; 473 | unsigned char output[16] = {0}; 474 | unsigned char plaintext[16] = {0}; 475 | unsigned char plainout[256] = {0}; 476 | int po_index = 0 ; 477 | if (_length % 16 == 0) { 478 | rounds = _length / 16; 479 | } else { 480 | rounds = _length / 16 + 1; 481 | } 482 | 483 | int start = 0; 484 | int end = 0; 485 | 486 | for (int j = 0; j < rounds; j++) { 487 | start = j * 16; 488 | end = start + 16; 489 | if ( end > _length) { 490 | end = _length; 491 | } 492 | memset(ciphertext, 0, 16); 493 | memcpy(ciphertext, _in + start, end - start); 494 | if ( m_mode == MODE_CFB ) { 495 | if (first_round == true) { 496 | m_aes->Cipher(m_iv, output); 497 | first_round = false; 498 | } else { 499 | m_aes->Cipher(input, output); 500 | } 501 | for (int i = 0; i < 16; i++) { 502 | if ( end - start - 1 < i) { 503 | plaintext[i] = output[i] ^ 0; 504 | } else { 505 | plaintext[i] = output[i] ^ ciphertext[i]; 506 | } 507 | } 508 | for (int k = 0; k < end - start; ++k) { 509 | plainout[po_index++] = plaintext[k]; 510 | } 511 | //memset(input, 0, 16); 512 | memcpy(input, ciphertext, 16); 513 | } else if (m_mode == MODE_OFB) { 514 | if (first_round == true) { 515 | m_aes->Cipher(m_iv, output); 516 | first_round = false; 517 | } else { 518 | m_aes->Cipher(input, output); 519 | } 520 | for (int i = 0; i < 16; i++) { 521 | if ( end - start -1 < i) { 522 | plaintext[i] = 0 ^ ciphertext[i]; 523 | first_round = false; 524 | } else { 525 | plaintext[i] = output[i] ^ ciphertext[i]; 526 | } 527 | } 528 | for (int k = 0; k < end - start; ++k) { 529 | plainout[po_index++] = plaintext[k]; 530 | } 531 | memcpy(input, output, 16); 532 | } else if (m_mode == MODE_CBC) { 533 | printf("------ciphertext------"); 534 | print(ciphertext, 16); 535 | printf("----------------------\n"); 536 | m_aes->InvCipher(ciphertext, output); 537 | printf("------output------"); 538 | print(output, 16); 539 | printf("----------------------\n"); 540 | for (int i = 0; i < 16; ++i) { 541 | if ( first_round == true) { 542 | plaintext[i] = m_iv[i] ^ output[i]; 543 | } else { 544 | plaintext[i] = input[i] ^ output[i]; 545 | } 546 | } 547 | first_round = false; 548 | for ( int k = 0; k < end - start; ++k) { 549 | plainout[po_index++] = plaintext[k]; 550 | } 551 | memcpy(input, ciphertext, 16); 552 | } else { 553 | // TODO 554 | } 555 | } 556 | memcpy(_out, plainout, po_index); 557 | return po_index; 558 | } 559 | 560 | -------------------------------------------------------------------------------- /AES.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FileName : AES.h 3 | * 4 | */ 5 | #ifndef __AES_H__ 6 | #define __AES_H__ 7 | 8 | #include 9 | 10 | extern void print(unsigned char* state, int len); 11 | 12 | class AES 13 | { 14 | public: 15 | AES(unsigned char* key = NULL); 16 | virtual ~AES(); 17 | void SetKey(unsigned char *key); 18 | unsigned char* Cipher(unsigned char* input, unsigned char* output); 19 | unsigned char* InvCipher(unsigned char* input, unsigned char* output); 20 | void* Cipher(void* input, void *output, int length=0); 21 | void* InvCipher(void* input,void *output, int length); 22 | 23 | private: 24 | unsigned char Sbox[256]; 25 | unsigned char InvSbox[256]; 26 | unsigned char w[11][4][4]; 27 | 28 | void KeyExpansion(unsigned char* key, unsigned char w[][4][4]); 29 | unsigned char FFmul(unsigned char a, unsigned char b); 30 | 31 | void SubBytes(unsigned char state[][4]); 32 | void ShiftRows(unsigned char state[][4]); 33 | void MixColumns(unsigned char state[][4]); 34 | void AddRoundKey(unsigned char state[][4], unsigned char k[][4]); 35 | 36 | void InvSubBytes(unsigned char state[][4]); 37 | void InvShiftRows(unsigned char state[][4]); 38 | void InvMixColumns(unsigned char state[][4]); 39 | }; 40 | 41 | enum AESMode_t { MODE_OFB = 1, MODE_CFB, MODE_CBC, MODE_ECB }; 42 | class AESModeOfOperation { 43 | private: 44 | AES *m_aes; 45 | AESMode_t m_mode; 46 | unsigned char m_key[16]; 47 | unsigned char m_iv[16]; 48 | // bool m_firstround; 49 | public: 50 | AESModeOfOperation(); 51 | ~AESModeOfOperation(); 52 | void set_mode(AESMode_t _mode); 53 | //AESMode_t get_mode(); 54 | void set_key (unsigned char *key); 55 | void set_iv(unsigned char *iv); 56 | int Encrypt(unsigned char *input, int length, unsigned char *output); 57 | int Decrypt(unsigned char *input, int length, unsigned char *output); 58 | }; 59 | 60 | 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | AESCipher 2 | support AES core, and CFB, OFB, CBC, ECB 3 | -------------------------------------------------------------------------------- /Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "AES.h" 3 | 4 | void print(unsigned char* state, int len); 5 | 6 | int main(int argc, char* argv[]) 7 | { 8 | unsigned char input[] = {84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116, 33, 84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116, 33, 84, 104, 105, 115, 32, 105, 115, 32, 97, 46}; 9 | unsigned char iv[] = {103,35,148,239,76,213,47,118,255,222,123,176,106,134,98,92}; 10 | unsigned char key[] = {143,194,34,208,145,203,230,143,177,246,97,206,145,92,255,84}; 11 | unsigned char output[100] ={0}; 12 | unsigned char temp[100] = {0}; 13 | // unsigned char 14 | AESModeOfOperation moo; 15 | moo.set_key(key); 16 | moo.set_mode(MODE_OFB); 17 | moo.set_iv(iv); 18 | int olen = sizeof input; 19 | 20 | memcpy(temp, input, sizeof input); 21 | int len = moo.Encrypt(temp, olen, output); 22 | printf("len = %d\n", len); 23 | printf("output"); 24 | print(output, len); 25 | printf("\n\nDecrypt----------\n"); 26 | len = moo.Decrypt(output, len, input); 27 | printf("len = %d\n", len); 28 | printf("input"); 29 | print(input, len); 30 | 31 | return 0; 32 | } 33 | 34 | void print(unsigned char* state, int len) 35 | { 36 | int i; 37 | for(i=0; i15 ? "" : "0", state[i]); 41 | printf("%d ", (int)(state[i] & 0xff)); 42 | } 43 | printf("\n"); 44 | } 45 | 46 | --------------------------------------------------------------------------------