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

char uctbl[64]={
   ' ', '"', '\'','~', '.', '.', '.', '<',    // 000
   '>', '^',  0,   0,   0,   0,   0,   0,     // 010
   ' ', '?', 'S', 'T', 'U', 'V', 'W', 'X',     // 020
   'Y', 'Z', ' ', '=',  0,   0, '\t', ' ',    // 030
   '-', 'J', 'K', 'L', 'M', 'N', 'O', 'P',     // 040
   'Q', 'R', '!', '$', '+', ']', '|', '[',     // 050
    0,  'A', 'B', 'C', 'D', 'E', 'F', 'G',     // 060
   'H', 'I',  0, 0xd7,  0,   8,   0, '\n' };  // 070

char lctbl[64]={
   ' ', '1', '2', '3', '4', '5', '6', '7',     // 000
   '8', '9',  0,   0,   0,   0,   0,   0,     // 010
   '0', '/', 's', 't', 'u', 'v', 'w', 'x',     // 020
   'y', 'z', ' ', ',',  0,   0, '\t', ' ',    // 030
   '_', 'j', 'k', 'l', 'm', 'n', 'o', 'p',     // 040
   'q', 'r', '!', '$', '-', ')',  0,  '(',     // 050
    0,  'a', 'b', 'c', 'd', 'e', 'f', 'g',     // 060
   'h', 'i',  0,  '.',  0,   8,   0, '\n' };  // 070

#define LC 072
#define UC 074
#define BS 075
#define BLACK 034
#define RED 035

int uc=0;

void outchr(char c){
	char outc;

	if(c == 077) return;
        if(c == UC){ uc = 1; return;}
        if(c == LC){ uc = 0; return;}
        if((c == RED)||(c == BLACK)) return;
          
        if(uc)
         outc = (uctbl[c]);
        else
         outc = (lctbl[c]);
        if(outc) putchar(outc); else printf("<<%03o>> ",c);
}

int main()
{
	int wrd;
	int i,j;
	int blk=0;
	unsigned int line[8];
	unsigned char c;
	unsigned long int dchar;



	while(1)
	{
	 uc =0;
	 // one dectape block
	 for(i=0; i<256; i++){
	  if(i==0) printf("\n%04o:0000 ",blk);
// pack into 18 bit word
	  wrd =  (getchar()&0x3f)<<12; 
	  wrd |= (getchar()&0x3f)<<6; 
	  wrd |= (getchar()&0x3f);
	  printf("%06o ", wrd);
	  line[i&7] = wrd;

	  if((i&7)==7){
	   for(j=0; j<8; j++){
	    c = (line[j] & 0770000) >> 12;
	    outchr(c);
	    c = (line[j] & 0007700) >> 6;
	    outchr(c);
	    c =  line[j] & 0000077;
	    outchr(c);
	   }
	   if(i != 0377) printf("\n%04o:%04o ",blk,i); else printf("\n");
	  }
	  fflush(stdout);
	 }
	 blk++;
	 if(blk >= 608) exit(0);
	}

}

