fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void usage(char *);
  6. void enshirt(char *);
  7. void deshirt(char *);
  8.  
  9. const char table[16] = {0x1f, 0x07, 0x09, 0x01, 0x0b, 0x02, 0x05, 0x05, 0x03,
  10. 0x11, 0x28, 0x0c, 0x23, 0x16, 0x1b, 0x02};
  11.  
  12. int
  13. main(int argc, char *argv[])
  14. {
  15. if (argc < 3)
  16. usage(argv[0]);
  17.  
  18. if (strncmp(argv[1], "-e", 2) == 0)
  19. enshirt(argv[2]);
  20. else if (strncmp(argv[1], "-d", 2) == 0)
  21. deshirt(argv[2]);
  22. else
  23. usage(argv[0]);
  24.  
  25. exit(0);
  26. }
  27.  
  28. void usage(char *progname)
  29. {
  30. printf("Usage: ./%s [-e] [-d] filename\n", progname);
  31. exit(1);
  32. }
  33.  
  34. void deshirt(char *filename)
  35. {
  36. int i;
  37. char cp, *line;
  38. FILE *fp;
  39.  
  40. if ((fp = fopen(filename, "r")) == NULL) {
  41. printf("Unable to open: %s\n", filename);
  42. exit(1);
  43. }
  44.  
  45. fgets(line, 10, fp);
  46.  
  47. if (strncmp(line, "redshirt2", 9) == 0) {
  48. fseek(fp, 9L, SEEK_SET);
  49. } else {
  50. printf("Error: Not a redshirt2 file\n");
  51. exit(1);
  52. }
  53.  
  54. while (cp != EOF) {
  55. cp = fgetc(fp);
  56. if (cp > 0x20) {
  57. i++;
  58. i %= 16;
  59. cp -= table[i];
  60.  
  61. if (cp < 0x20)
  62. cp += 0x5f;
  63. }
  64. printf("%c", cp);
  65. }
  66.  
  67. return;
  68. }
  69.  
  70. void enshirt(char *filename)
  71. {
  72. int i;
  73. char cp;
  74. FILE *fp;
  75.  
  76. if ((fp = fopen(filename, "r")) == NULL) {
  77. printf("Unable to open: %s\n", filename);
  78. exit(1);
  79. }
  80.  
  81. printf("redshirt2");
  82.  
  83. while (cp != EOF) {
  84. cp = fgetc(fp);
  85. if (cp > 0x20) {
  86. i++;
  87. i %= 16;
  88. cp += table[i];
  89.  
  90. if (cp < 0x20)
  91. cp -= 0x5f;
  92. }
  93. printf("%c", cp);
  94. }
  95.  
  96. return;
  97. }
  98.  
Runtime error #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Usage: ././prog [-e] [-d] filename