[原创][hubuctf 2022 新生赛]simple-ag真人国际厅网站

#include

#include

#include

 

char base64charsarr[] = "qvejafhmuyjbac u8ph5n9od17fricl/x0gvtm4qk6t2z3wnssyoebilxwkgzprd";

 

void base64decode(char str[]) {

    int length = strlen(str);

    int padding = 0;

 

    // 计算填充字符数量

    if (str[length - 1] == '=') {

        padding ;

        if (str[length - 2] == '=')

            padding ;

    }

 

    // 计算解码后的字符数量

    int decodedlength = (length * 3) / 4 - padding;

 

    // 分配存储解码结果的内存

    char* decodedstr = (char*)malloc(decodedlength 1);

 

    int outindex = 0;

    for (int i = 0; i < length; i = 4) {

        char char1 = -1, char2 = -1, char3 = -1, char4 = -1;

 

        // 查找每个字符在base64字符集中的索引

        for (int j = 0; j < 64; j ) {

            if (base64charsarr[j] == str[i]) {

                char1 = j;

                break;

            }

        }

 

        for (int j = 0; j < 64; j ) {

            if (base64charsarr[j] == str[i 1]) {

                char2 = j;

                break;

            }

        }

 

        for (int j = 0; j < 64; j ) {

            if (base64charsarr[j] == str[i 2]) {

                 char3 = j;

                break;

            }

        }

 

        for (int j = 0; j < 64; j ) {

            if (base64charsarr[j] == str[i 3]) {

                 char4 = j;

                break;

            }

        }

 

        // 解码并存储结果

        decodedstr[outindex ] = (char1 << 2) | ((char2 & 0x30) >> 4);

        if (char3 != -1)

            decodedstr[outindex ] = ((char2 & 0xf) << 4) | ((char3 & 0x3c) >> 2);

        if (char4 != -1)

            decodedstr[outindex ] = ((char3 & 0x3) << 6) | char4;

    }

 

    // 添加字符串结束符

    decodedstr[decodedlength] = '\0';

 

    printf("decoded string: %s\n", decodedstr);

 

    // 释放内存

    free(decodedstr);

 

int main() {

    char str[100]="5mc58bphliax7j8ocjilavuxajvmcoymaopmaofg15c475tschfm/8=="; // example base64 encoded string

    base64decode(str);

    return 0;

原文链接:https://bbs.kanxue.com/thread-278038.htm

网络摘文,本文作者:15h,如若转载,请注明出处:https://www.15cov.cn/2023/08/27/原创hubuctf-2022-新生赛simple_re/

发表评论

邮箱地址不会被公开。 必填项已用*标注

网站地图