Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by petter wahlman, http://www.twitter.com/badeip
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <string.h>
- #define ROTATION 13
- static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- void decodeblock(unsigned char *input, char *output)
- {
- unsigned char out[4];
- out[0] = input[0] << 2 | input[1] >> 4;
- out[1] = input[1] << 4 | input[2] >> 2;
- out[2] = input[2] << 6 | input[3] >> 0;
- out[3] = '\0';
- strncat(output, (const char *)out, sizeof(out));
- }
- char *unbase(char *input)
- {
- int c, phase, i;
- unsigned char in[4];
- char *output;
- char *p;
- output = calloc(1, strlen(input) << 1);
- phase = 0;
- i = 0;
- while(input[i]) {
- c = input[i];
- if('=' == c) {
- decodeblock(in, output);
- break;
- }
- p = strchr(b64, c);
- if (p) {
- in[phase] = p - b64;
- phase = (phase + 1) % 4;
- if (phase == 0) {
- decodeblock(in, output);
- in[0]=in[1]=in[2]=in[3]=0;
- }
- }
- i++;
- }
- return output;
- }
- int rotate(char c, int pos)
- {
- char alpha[pos << 1];
- int i;
- for (i = 0; i < sizeof(alpha); i++)
- alpha[i] = 'a' + i;
- return (c < alpha[0] || c > alpha[sizeof(alpha)-1]) ? c : alpha[(c + (sizeof(alpha) >> 1) - alpha[0]) % sizeof(alpha)];
- }
- void revert(char *str)
- {
- char c;
- int i;
- for (i = 0; i < (strlen(str) >> 1); i++) {
- c = str[i];
- str[i] = str[strlen(str)-i - 1];
- str[strlen(str) -i - 1] = c;
- }
- }
- int main(int argc, char **argv)
- {
- char challenge[] = "=ImYndmbn1ieiBnLmJWdjJmZ";
- char *unbased;
- int i, r;
- revert(challenge);
- unbased = unbase(challenge);
- for (i = 0; i < strlen(unbased); i++) {
- r = rotate(unbased[i], 13);
- if (r < 1)
- break;
- printf("%c", r);
- }
- putchar('\n');
- free(unbased);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement