#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <exec/types.h>

#include "Owners.h"


int decryptowner(char *, ULONG);

int decryptowner(char *s, ULONG sn)

{char  buf[60];
 int   rc = 0;
 int   i,j;
 int   ctr;
 int   cnt;
 char *r;
 char *rr;
 int   ssn;

 cnt = 0;
 for(i = 0;; i++)
    {r = (char *)&enc[i];
     if (r[0]==0 && r[1]==0 && r[2]==0)
         break;

     for(j = 0; j < 60; j++)
   {r[j] ^= encrypt3[cnt];
        }
     cnt++;
      
     if (cnt >= strlen(encrypt3)) cnt = 0;

     ctr = 0;
     for(j=0;j<60;j++)
        {r[j] ^= encrypt2[ctr];
         ctr++;
         if (ctr>=strlen(encrypt2))  ctr = 0;
        }

     ctr = 0;
     for(j=0;j<60;j++)
        {r[j] ^= encrypt1[ctr];
         ctr++;
         if (ctr>=strlen(encrypt1))  ctr = 0;
   }
    }

 for(i=0;;i++)
    {r = (char *)&enc[i];
     if (r[0]==0)  break;

     rr = r;
     rr = stpblk(r);
     ssn = atoi(rr);

     if (ssn==(int)sn)
        {rc = 1;
         strncpy(buf,r+17,60);
         buf[59]=0;
         break;
        }
    }

 for(j=strlen(buf)-1;buf[j]==32;j--)
    {buf[j]=0;
    }

 sprintf(s, "Registered to %s", buf);
 for(i=0;;i++)
    {r=(char *)&enc[i];
     if (r[0]==0)  break;

     for(j=0;j<60;j++)
         r[j] = 1;
    }

 return(rc);
}
