view quickrypt.c @ 15:7466927c17a5

webtty.js: check message order. Implement checking the numbers of the client's messages on the server. Fixing out-of-ordering isn't implemented because the problem hasn't been observed yet, though it likely will once actual network transit is involved.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 15 May 2012 16:26:28 -0700
parents 9bef0941c6dd
children
line wrap: on
line source

/*
 * quickrypt: a quick and dirty crypt(3) utility for use with node.js.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crypt.h>

int main(int argc, char *argv[]) {
  char clear[32], enc[120], *ptr;
  fgets(&clear, 32, stdin);
  if (!(ptr = strchr(&clear, '\n')))
    return 1;
  else
    *ptr = '\0';
  fgets(&enc, 120, stdin);
  if (!(ptr = strchr(&enc, '\n')))
    return 1;
  else
    *ptr = '\0';
  ptr = crypt(clear, enc);
  if (!strcmp(argv[argc - 1], "-s")) {
    /* Option -s for "show": output the encrypted version. */
    printf("%s\n", ptr);
    return 0;
  }
  /* Otherwise this is a check. */
  else if (!strcmp(ptr, enc))
    return 0;
  return 1;
}