MicroMint demo program

New Message Reply About this list Date view Thread view Subject view Author view

Robert Hettinga (rah@shipwright.com)
Sat, 27 Mar 1999 20:50:59 -0500


--- begin forwarded text

Date: Sat, 27 Mar 1999 19:02:38 -0500
To: Digital Bearer Settlement List <dbs@philodox.com>
From: Robert Hettinga <rah@shipwright.com>
Subject: MicroMint demo program
Sender: <dbs@philodox.com>
List-Subscribe: <mailto:requests@philodox.com?subject=subscribe%20dbs>

--- begin forwarded text

Date: Sun, 28 Mar 1999 00:17:19 +0300
From: Vadim Fedukovich <vf@usb.gf.unity.net>
To: rah@shipwright.com
Subject: MicroMint demo program

Hello Robert,

would you please take a look at the program attached?
I write it just to be sure I'm understand MicroMint basics.
Any comments on it's quality? Please feel free to do whatever
you want with it.

Than you for wonderful FC99 story,
Vadim Fedukovich
/*
 * MicroMint demo coin generator
 * according to paper "PayWord and MicroMint: Two simple micropayment schemes"
 * by Ronald Rivest and Adi Shamir
 *
 * written by Vadim Fedukovich
 * usage terms to be defined by Robert Hettinga
 * best compiled with "gcc -Wall -O6 -o mmint mint.c"
 *
 * $Log: mint.c,v $
 * Revision 1.2 1999/03/27 23:45:51 vf
 * Add good/wrong balls functionality to do more generation than storage
 *
 * Revision 1.1.1.1 1999/03/27 21:27:53 vf
 * Initial check-in. Very basic functionality. Generates just one single coin.
 * Really simple hash function for speed and small storage.
 *
 */
char *version = "$Id: mint.c,v 1.2 1999/03/27 23:45:51 vf Exp $";

#include <stdio.h>
#include <stdlib.h>

/* really simple hash() suitable for demonstration only */
#define HS unsigned
HS hash(long);

/* given ball and a sample to compare with returns true and fill bin index */
int isGood(long ball, unsigned int series, unsigned int *index);

#define WAYS 4 /* 4-way hash collision for original paper */
typedef struct _bin {
  long balls[WAYS];
  int num; /* how many hash values were saved already */
} BIN;
#define NUMBINS 256

int main() {
  unsigned int seed = 33322; /* put your own source of randomness here */
  int idx, balls, gb, i;
  long try;
  BIN bins[NUMBINS], *ptr;
  unsigned mask = 0x3C; /* coin brand for this month */

  printf("Running MicroMint version: %s\n", version);

  /* init it */
  for(i=0; i < NUMBINS; i++) {
    bins[i].num = 0;
  }
  srandom(seed);

  /* start tossing... */
  for(balls=0,gb=0;;balls++) { /* estimate for work reqired to generate
1st coin */
    try = random(); /* pick a ball */
    if(!isGood(try, mask, &idx))
      continue; /* drop wrong one */
    gb++;
    ptr = bins + idx; /* a bin to toss it at */
    ptr->balls[(ptr->num)++] = try; /* save it there */

    /* stop on 1st coin ready */
    if(ptr->num == WAYS)
      break;
  }

  /* print it */
  printf("A coin (represented as %d-way hash collision) generated:\n", WAYS);
  for(i=0; i<WAYS; i++)
    /* count balls starting from 1 (not 0) for normal people */
    printf("Ball-%d: %ld (hash: %d)\n", i+1, (try = ptr->balls[i]), hash(try));
  printf("Work done: %d balls (%d good) tossed\n", balls, gb);

  return 0;
}

HS hash(long sample) {
/* WARNING: *too* simple hash for speed; demo-only mode */
/* WARNING: only 64k possible outcomes (256 good) to reduce storage required */
  return((HS)(sample & 0xffff));
}

int isGood(long ball, unsigned int series, unsigned int *index) {
/* 256-fold generator's work required */
  if(((ball >> 8) & 0xff) != series)
    return 0; /* wrong ball, drop it */
  *index = ball & 0xff ;
  return 1;
}

--- end forwarded text

-----------------
Robert A. Hettinga <mailto: rah@philodox.com>
Philodox Financial Technology Evangelism <http://www.philodox.com/>
44 Farquhar Street, Boston, MA 02131 USA
"... however it may deserve respect for its usefulness and antiquity,
[predicting the end of the world] has not been found agreeable to
experience." -- Edward Gibbon, 'Decline and Fall of the Roman Empire'

--- end forwarded text

-----------------
Robert A. Hettinga <mailto: rah@philodox.com>
Philodox Financial Technology Evangelism <http://www.philodox.com/>
44 Farquhar Street, Boston, MA 02131 USA
"... however it may deserve respect for its usefulness and antiquity,
[predicting the end of the world] has not been found agreeable to
experience." -- Edward Gibbon, 'Decline and Fall of the Roman Empire'


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:18:50