2023年エントロピーカップの第1レベルの簡単な分析

暗号文は32バイトであることが知られており、暗号化されたソースコードは以下のようになります。平文のパスワードを取得するには、暗号化されたソースコードに基づいて復号コードを取得する必要があります。

暗号文:
6B562E2D3E7B6C61636078616C666C62

#include <stdio.h>

void reverseBits(unsigned char* パスワード) {     int i, j;     unsigned char temp;

    for (i = 0; i < 16; i++) {         temp = 0;         for (j = 0; j < 8; j++) {             temp |= ((password[i] >> j) & 1) << (7 - j);         パスワード[i] = 一時         ;     } }






void swapPositions(unsigned char* パスワード) {     int i;     unsigned char temp[16];     int 位置[16] =             {                     13, 4, 0, 5,                     2, 12, 11, 8,                     10, 6, 1, 9, 3,                     15, 7, 14             };








    for (i = 0; i < 16; i++) {         temp[位置[i]] = パスワード[i];     }

    for (i = 0; i < 16; i++) {         パスワード[i] = temp[i];     } }


void leftShiftBytes(unsigned char* パスワード) {     for (int i = 0; i < 16; i++) {         パスワード[i] = パスワード[i] << 3 | パスワード[i] >> 5;     } }



void xorWithKeys(unsigned char* パスワード、unsigned int ラウンド) {     int i;     for (i = 0; i < 16; i++) {         パスワード[i] ^= (符号なし文字)(0x78 * 丸め & 0xFF);     } }




void encryptPassword(unsigned char* パスワード) {     int i;     unsigned int ラウンド;

    for (round = 0;round < 16;round++) {         reverseBits(パスワード);         swapPositions(パスワード);         leftShiftBytes(パスワード);         xorWithKeys(パスワード、ラウンド);     } }





int main() {     unsigned char パスワード[17] = "1234567890";     printf("暗号化前のパスワードは次のとおりです:\n");     for (int i = 0; i < 16; i++) {         printf("%02X " , パスワード[i]);     }     encryptPassword(パスワード);     printf("暗号化されたパスワードは:\n");     for (int i = 0; i < 16; i++) {         printf("%02X ", パスワード[ i ]);     }     printf("\n");     0 を返す; }












分析: 考え方は比較的単純です。復号化は暗号化の逆のプロセスです。一度実行するだけです。

復号化コードは次のとおりです。

#include <stdio.h>

void reverseBits_dec(unsigned char* パスワード) {

    int i, j;

    unsigned char temp;

    for (i = 0; i < 16; i++) {

        温度 = 0;

        for (j = 0; j < 8; j++) {

            temp |= ((パスワード[i] >> (7 - j)) & 1) << j;

        }

        パスワード[i] = 一時;

    }

}

void swapPositions_dec(unsigned char* パスワード) {

    int i;

    unsigned char temp[16];

    int 位置[16] =

            {

                    13、4、0、5、

                    2、12、11、8、

                    10、6、1、9、

                    3、15、7、14

            };

    for (i = 0; i < 16; i++) {

        temp[i] = パスワード[位置[i]];

    }

    for (i = 0; i < 16; i++) {

        パスワード[i] = 一時[i];

    }

}

void leftShiftBytes_dec(unsigned char* パスワード) {

    for (int i = 0; i < 16; i++) {

        パスワード[i] = パスワード[i] >> 3 | パスワード[i] << 5;

    }

}

void xorWithKeys_dec(unsigned char* パスワード、unsigned int ラウンド) {

    int i;

    for (i = 0; i < 16; i++) {

        パスワード[i] ^= (符号なし文字)(0x78 * 丸め & 0xFF);

    }

}

void encryptPassword_dec(unsigned char* パスワード) {

    int i;

    unsigned int ラウンド;

    for (ラウンド = 16; ラウンド >= 1; ラウンド--) {

        xorWithKeys_dec(password,round-1); //処理関数は変更されず、パラメータを変更するだけです

        leftShiftBytes_dec(password); //暗号化は左に 3 ビット回転し、復号化は右に 3 ビット回転します

        swapPositions_dec(password); //位置行列は変更されず、index<-->value

        reverseBits_dec(password); //ビットを反転して逆処理を行うだけです

    }

}

int main() {

    符号なし文字パスワード[17] = {0x6B,0x56,0x2E,0x2D,0x3E,0x7B,0x6C,0x61,0x63,0x60,0x78,0x61,0x6C,0x66,0x6C,0x62};

    printf("暗号化されたパスワードは次のとおりです:\n");

    for (int i = 0; i < 16; i++) {

        printf("%02X ", パスワード[i]);

    }

    printf("\n");

    encryptPassword_dec(パスワード);

    printf("暗号化前のパスワードは次のとおりです:\n");

    for (int i = 0; i < 16; i++) {

        printf("%c", パスワード[i]);

    }

    printf("\n");

    0を返します。

}

実行結果は次のとおりです。

-------------------------------------------------- --

暗号化後のパスワードは
6B 56 2E 2D 3E 7B 6C 61 63 60 78 61 6C 66 6C 62 
暗号化前のパスワードは
pdksidicndjh%^&6

-------------------------------------------------- ---

おすすめ

転載: blog.csdn.net/ryanzzzzz/article/details/132294370