Facebook
From Sweet Cassowary, 3 Years ago, written in Plain Text.
This paste is a reply to Untitled from Gracious Cheetah - view diff
Embed
Download Paste or View Raw
Hits: 53
  1. #include <stdio.h>                        // compiler directive
  2. #include <string.h>
  3.  
  4. int main(void)                            // main function
  5. {
  6.     char E[62];                           // array store input char
  7.     char D[62];                           // array store output char
  8.     int i, j, max;                        // i, j for loop, max for
  9.                                           // string length
  10.     int find = 1;                         // not decode all yet
  11.  
  12.     while (find) {
  13.         scanf("%s", E);                   // input string
  14.         max = strlen(E);                  // get string length
  15.         if (E[0] == 0) {                  // terminate
  16.             find = 0;
  17.         }
  18.         if (find) {
  19.             for (i = 1; i <= max ; i++) { // minus a space
  20.                 E[i] = E[i] - ' ';
  21.             }
  22.         }
  23.         for (i = 1, j = 0; i <= max, j <= max ; i = i + 4, j = j + 3) {
  24.             D[j] = (E[i] << 2) + (E[i + 1] >> 4);       // shift to decode
  25.             D[j + 1] = (E[i + 1] << 4) + (E[i + 2] >> 2);
  26.             D[j + 2] = (E[i + 2] << 6) + E[i + 3];
  27.         }
  28.         for (j = 0; j < E[0]; j++) {
  29.             printf("%c", D[j]);           // print output
  30.         }
  31.     }
  32.     return 0;                             // return 0
  33. }
  34.