Linksys/Configuration

Some Linksys routers export their configuration data in an encoded format (possibly to avoid displaying plaintext passwords and to discourage users to tinker with the configuration files themselves).

However, this practice makes their equipment lousy for corporate tech support, since you have no easy way to check if a customer's router is correctly configured, make template configurations, etc.

Fortunately, it is possible to decode some of those files (mostly from WRT54 variants) using this small C program (taken from here).

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

int decode(unsigned char);

int
decode(unsigned char ch)
{
  ch = ~((ch << 2) | ((ch & 0xC0) >> 6));
  if (ch) {
    if (isprint(ch)) {
      return ch;
    } else {
      return ' ';
    }
  }
  return '\n';
}

int
main(int argc, char *argv[])
{
  int  ch;
  FILE *fp;

  if (argc < 2) {
    fp = stdin;
  } else {
    if (NULL == (fp = fopen(argv[1], "r"))) {
      fprintf(stderr, "Error:  Cannot open file %s\n", argv[1]);
      exit(EXIT_FAILURE);
    }
  }

  while (EOF != (ch =fgetc(fp))) {
    fputc(decode(ch), stdout);
  }
  return EXIT_SUCCESS;
}