[Cryptography] Rolling code "Hello World"

Henry Baker hbaker1 at pipeline.com
Sun Feb 25 11:42:15 EST 2018


I wanted to demonstrate rolling codes with the simplest Linux "Hello World" crypto program.

Critiques?  (No nasty remarks re Lispy formatting!)

alice.c:

// Alice receives mod 13 integers from Bob/Mallory/Oscar via stdin.

// Bob/Mallory/Oscar are the garage door senders; Alice is the garage door opener receiver.
// Oscar is Bob sending "out of range".  Alice allows at most 1 Oscar for every Bob.
// Alice doesn't increment when no match to avoid DOS.

#include <stdio.h>

#define MYINC(n) ((2*n)%13)

int main(void)
{ unsigned int ctr=1,input=0;
  printf("Alice starting: ctr=%u\n",ctr);
  while (scanf("%u",&input)==1)
    { printf("Alice: input=%u ctr=%u",input,ctr);
      if (input==ctr) {printf(" ok\n"); ctr=MYINC(ctr);}
      else if (input==MYINC(ctr)) {printf(" uh, ok\n"); ctr=MYINC(MYINC(ctr));}
      else printf(" probably Mallory; ignored\n"); } }

bob.c:

#include <stdio.h>

#define MYINC(n) ((2*n)%13)

int main(void)
{ char ch=0; unsigned int ctr=1, malloryctr=0;
  fprintf(stderr,"Bob starting: ctr=%u\n",ctr);
  while ((ch=getchar()) && (ch!=EOF))
    switch (ch)
      { case 'b':
	  fprintf(stderr,"Keypress Bob\n");
	  printf("%u\n",ctr); fflush(stdout);
	  malloryctr=ctr; ctr=MYINC(ctr);
	  break;
        case 'o':
	  fprintf(stderr,"Keypress Oscar\n");
	  ctr=MYINC(ctr);
	  break;
        case 'm':
	  fprintf(stderr,"Keypress Mallory\n");
	  printf("%u\n",malloryctr); fflush(stdout);
	  break; }
  fprintf(stderr,"Bob: quitting...\n"); }

---

Execute:

% ./bob | ./alice



More information about the cryptography mailing list