int main(int argc, char **argv) { unsigned char destmp[TXTSIZ], desptx[TXTSIZ], desctx[TXTSIZ], deskey[8]; int i; /***************************************************************************** * Encipher some data using DES in CBC mode. * *****************************************************************************/ fprintf(stdout, "Enciphering with DES in CBC mode\n"); deskey[0] = 0x01; deskey[1] = 0xf1; deskey[2] = 0x23; deskey[3] = 0x4a; deskey[4] = 0x1f; deskey[5] = 0x22; deskey[6] = 0x00; deskey[7] = 0xee; for (i = 0; i < TXTSIZ; i++) destmp[i] = (i * 23) % 256; cbc_encipher(destmp, desctx, deskey, TXTSIZ); cbc_decipher(desctx, desptx, deskey, TXTSIZ); fprintf(stdout, "deskey: %02x %02x %02x %02x %02x %02x %02x %02x\n", deskey[0], deskey[1], deskey[2], deskey[3], deskey[4], deskey[5], deskey[6], deskey[7]); for (i = 0; i < TXTSIZ; i++) { if (destmp[i] == desptx[i]) fprintf(stdout, "destmp[%03d]=%02x, desctx[%03d]=%02x, desptx[%03d]=" "%02x (OK)\n", i, destmp[i], i, desctx[i], i, desptx[i]); else fprintf(stdout, "destmp[%03d]=%02x, desctx[%03d]=%02x, desptx[%03d]=" "%02x (ERROR)\n", i, destmp[i], i, desctx[i], i, desptx[i]); } return 0; }
int main() { int size = 16, i; char plaintext[] = "hello world, thi"; char ciphertext[size], deciphered[size]; char key[8] = "abcdefgh"; printf("plaintext = '%s', hex:\n", plaintext); hex_dump(plaintext, size); printf("\n\n"); cbc_encipher(plaintext, ciphertext, key, size); printf("ciphertext = '%s', hex:\n", ciphertext); hex_dump(ciphertext, size); printf("\n\n"); cbc_decipher(ciphertext, deciphered, key, size); printf("deciphered = '%s', hex:\n", deciphered); hex_dump(deciphered, size); printf("\n\n"); return 0; }