On Sun, Jun 15, 2008 at 10:56 PM, buyoppy <[EMAIL PROTECTED]> wrote:

>  I saw a webpage of Solaris's 'isencrypted' function which
> inspects some data in a buffer is encrypted or not using
> some algorithm including statistical analysis. But now I
> cannot find that page on the Internet...


Try this implementation, which I have not tested (or even compiled).

#include <stdlib.h>
#include <zlib.h>

enum {
  PLANB_BUF_SIZE = 512;
  INADEQUATELY_EXPLAINED_MAGIC_NUMBER = 5;
};

static int incompressible(const char *inbuf, size_t len,
                        char *outbuf, size_t outlen) {
  int rv = compress2(outbuf, outlen, inbuf, len,
                     INADEQUATELY_EXPLAINED_MAGIC_NUMBER);
  if (Z_BUF_ERROR == rv)
    return 0;                   /* it grew. */
  else if (Z_MEM_ERROR == rv)
    return -1;                  /* meh, it's a guess. */
  else
    return rv > len;
}


int isencrypted(const char *buf, size_t len) {
  int retval;
  char planb_buf[PLANB_BUF_SIZE];
  void *out = malloc(len);
  if (out) {
    retval = incompressible(buf, len, out, len);
    free (out);
    return retval;
  } else {
    return incompressible(buf, PLANB_BUF_SIZE, planb_buf, PLANB_BUF_SIZE);
  }
}


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to