Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*******************
- 0 1 2 3 4 5 6 7 8 9 ' '
- _ . _ _ . _ _ _ _ _ .
- |.| ..| ._| ._| |_| |_. |_. ..| |_| |_| ...
- |_| ..| |_. ._| ..| ._| |_| ..| |_| ._| ...
- 0: 1 101 111
- 1: 0 001 001
- 2: 1 011 110
- 3: 1 011 011
- 4: 0 111 001
- 5: 1 110 011
- 6: 1 110 111
- 7: 1 001 001
- 8: 1 111 111
- 9: 1 111 011
- : 0 000 000
- | || || || || || || || || || || |
- 110111100010011011110101101101110011110011111011110010011111111111101100000000
- | 3 || i || b || 1 || t || z || z || 7 || y || f || / || s || A |
- */
- unsigned char base64_decode(char inp){
- if(inp == '+')
- return inp+19;
- if(inp == 057)
- return 63;
- if(inp >= 'a')
- return inp - 'a' + 26;
- if(inp < ':')
- return inp - '0' + 52;
- return inp - 'A';
- }
- int getBase64Bit(char *str, int pos){
- //printf("%2d", pos);
- int charNum = pos / 6;
- int bitNum = pos % 6;
- unsigned char c = base64_decode(str[charNum]);
- return c & 1 << (5 - bitNum);
- }
- typedef struct cons{
- char car;
- unsigned char count;
- struct cons *cdr;
- } cons_t;
- int getBase64Char(char *code, int offset, char c){
- if(c > 47){
- return getBase64Bit(code, offset + (c - '0')*7);
- }
- return getBase64Bit(code, offset + 70);
- }
- void buildChars(char *bt, char *code,int i, int offset, char c){
- if(i >= 3){
- return;
- }
- bt[i] = getBase64Char(code, offset + i, c) ? (i == 1?'_':'|'):' ';
- buildChars(bt, code, ++i, offset, c);
- }
- void printMidRow(char *code, cons_t *head, int offset){
- if(head == NULL){
- printf("\n");
- return;
- }
- //printf("hc %c", head->car);
- static char bt[3];
- buildChars(bt, code, 0, offset, head->car);
- printf(" %c%c%c", bt[0], bt[1], bt[2]);
- printMidRow(code, head->cdr, offset);
- }
- void reverse1(char *code, cons_t *head, cons_t *stack){
- //printf("%c", head->car);
- if(head->car == 0){
- printMidRow(code, stack, 1);
- printMidRow(code, stack, 4);
- }
- else{
- cons_t *nh = head->cdr;
- head->cdr = stack;
- reverse1(code, nh, head);
- }
- }
- void printTopRow(char *code, char *str, cons_t *head){
- if(str[0] == '\0'){
- printf("\n");
- reverse1(code, head, NULL);
- return;
- }
- cons_t newcons;
- (&newcons)->cdr = head;
- newcons.car = str[0];
- newcons.count = head->count+1;
- char bt = getBase64Char(code, 0, newcons.car)? '_' : ' ';
- printf(" %c%c ",str[0], bt);
- printTopRow(code, ++str, &newcons);
- }
- void nh (cons_t *h){
- h->car = 0;
- h->count = 0;
- h->count--;
- h->cdr = 0;
- }
- void main(int argc, char** argv){
- char * code = "3ib1tzz7yf/sA";
- cons_t head;
- nh(&head);
- if(argc<2){
- printf("ERROR: Please provide a single string as a command line argument.\nExample:\n./a.out '123 456'\n");
- return;
- }
- char *mstr = malloc(strlen(argv[1])+1);
- mstr[strlen(argv[1])] = '\0';
- for (int i= 0 ; i < strlen(argv[1]); i++){
- mstr[i] = argv[1][i];
- }
- printTopRow(code, mstr, &head);
- }
Advertisement
Add Comment
Please, Sign In to add comment