[Botan-devel] Stream cipher operations

Carlton Davis carlton at cs.mcgill.ca
Wed Oct 12 17:20:34 EDT 2005


Thanks for your feedback on my previous messages.
I did some testing on stream cipher operations, but
it seems as if I am doing something wrong. Here is the code:

  std::string passphrase = "testing"
  LibraryInitializer init;
  //Just testing here: a quick insecure way of getting a 128-bit key
  HashFunction* hash = get_hash("MD5");
  SymmetricKey skey = hash->process(passphrase)
  StreamCipher* cipher = get_stream_cipher("WiderWake4+1-BE");
  cipher->set_key(skey);

  unsigned short flag = 4;
  for (i = 0; i != sizeof(flag); i++)
    buf[i] = get_byte(i, flag);

  fprintf(stderr, "\nThe byte values are %x and %x\n",
          buf[0], buf[1]);
  cipher->encrypt(buf, 2);
  cipher->decrypt(buf, 2);
  fprintf(stderr, "\nAfter decryption, the byte values are %x and %x\n",
	  buf[0], buf[1]);

  unsigned short decryptflag = make_u16bit(buf[0], buf[1]);
  fprintf(stderr, "\nThe decrypted number is: %i\n", decryptflag);
--

I was expecting to get the same byte values after the
encryption/decryption operations, but here is the output:
-----
The byte values are 0 and 4

After decryption, the byte values are 6a and 46

The decrypted number is: 27206
-----

What am I doing wrong?

Thanks and best regards,

-Carlton




More information about the botan-devel mailing list