/*
 * by W.J.Hengeveld oct 1997
 *    itsme@xs4all.nl
 *
 * this is how cisco garbles its passwords for logging in on other machines
 * (the 'username' configuration lines)
 */
#include <stdio.h>
#include <stdlib.h>

char *masterkey="dsfd;kfoA,.iyewr";

char decryptchar(int key, int pos, char c)
{
   return c^masterkey[(key+pos)%16];
}

char *decrypt(char *str)
{
   int key;
   char tmpstr[3];
   static char plain[16];
   int i;
   int pos;
   char c;

   if (strlen(str)<2)
      return "";

   tmpstr[0]=str[0];
   tmpstr[1]=str[1];
   tmpstr[2]=0;
   key=strtol(tmpstr, 0, 10);
   for (pos=0, i=2 ; i<strlen(str) && pos<15; i+=2, pos++)
   {
      tmpstr[0]=str[i];
      tmpstr[1]=str[i+1];
      tmpstr[2]=0;
      c=strtol(tmpstr, 0, 16);
      plain[pos]=decryptchar(key, pos, c);
   }
   plain[pos]=0;

   return plain;
}

int main(int argc, char **argv)
{
   int i;
   for (i=1 ; i<argc ; i++)
   {
      printf("%s : %s\n", argv[i], decrypt(argv[i]));
   }
   return 0;
}


