看雪2019CTF第二场第六题:消失的岛屿

发布于 2019-06-20  41 次阅读


变异的base64解密

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
char index[] = "tuvwxTUlmnopqrs7YZabcdefghij8yz0123456VWXkABCDEFGHIJKLMNOPQRS9+/";
char  charEncrypt(int data)
{
    int dataa;
    dataa = index[data];
    if (dataa > 64 && dataa <= 90)
        return -101 - dataa;
    if (dataa > 96 && dataa <= 122)
        return dataa - 64;
    if (dataa > 47 && dataa <= 57)
        return dataa + 50;
    if (dataa == 43)
        return 119;
    if (dataa == 47)
        dataa = 121;
    return dataa;
}

char charDec(int data) {
    for (int i = 0; i <= 63; i++) {
        if (charEncrypt(i)==data)
        {
            return i;
        }
    }
    return -1;
}
int main(int argc, const char * argv[]) {
    char base64[64] = { 'A','B','C','D','E','F','G','H',
        'I','J','K','L','M','N','O','P','Q','R','S','T','U',
        'V','W','X','Y','Z','a','b','c','d','e','f','g','h'
        ,'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x',
        'y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
    char enc[] = "!NGV%,$h1f4S3%2P(hkQ94==";
    bool encold = 1;
    for (int i = 0; i < strlen(enc); i++) {
        int tmp_index=int(charDec(enc[i]));
        if (tmp_index != -1) {
            cout << base64[tmp_index];
        }
        else {
            cout << "=";
        }
    }
    cout << endl;
    system("pause");
    return 0;
}

运行结果

S2FuWHVlMjAxOWN0Zl9zdA==

base64解密即可。