#加解密總結

2020-10-22 15:00:48

0x00 簡介

培根密碼,培根所用的密碼是一種本質上用二進位制數設計的,沒有用通常的0和1來表示,而是採用a和b
培根密碼加密有兩種方式:
A aaaaa B aaaab C aaaba D aaabb E aabaa F aabab G aabba H aabbb I abaaa J abaab K ababa L ababb M abbaa N abbab O abbba P abbbb Q baaaa R baaab S baaba T baabb U babaa V babab W babba X babbb Y bbaaa Z bbaab
方式二:
a AAAAA g AABBA n ABBAA t BAABA
b AAAAB h AABBB o ABBAB u-v BAABB
c AAABA i-j ABAAA p ABBBA w BABAA
d AAABB k ABAAB q ABBBB x BABAB
e AABAA l ABABA r BAAAA y BABBA
f AABAB m ABABB s BAAAB z BABBB

通常加密者只需要兩種不同的字型或使用大小寫來代替ab即可,例如明文為bling,加密為:aaaab ababb abaaa abbab aabba,此時再隨意找句句子,使用大小寫來代替ab。密文如下:good GoOd STuDy day DAy Up hAHa

0x01 解密程式碼

#! python3
# -*- coding: utf-8 -*-
# @Time    : 2017/8/26 上午12:07
# @Author  : BlingBling
# @File    : Baconian.py
# @Software: PyCharm Community Edition
import re
class Baconian():
    alphabet = ['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']

    first_cipher = ["aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba", "aabbb", "abaaa", "abaab", "ababa",
                    "ababb", "abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "babaa", "babab",
                    "babba", "babbb", "bbaaa", "bbaab"]

    second_cipher = ["aaaaa", "aaaab", "aaaba", "aaabb", "aabaa", "aabab", "aabba", "aabbb", "abaaa", "abaaa", "abaab",
                     "ababa", "ababb", "abbaa", "abbab", "abbba", "abbbb", "baaaa", "baaab", "baaba", "baabb", "baabb",
                     "babaa", "babab", "babba", "babbb"]

    def __init__(self, str):
        self.str = str

    def decode(self):
        str = self.str.lower()
        str_array = re.findall(".{5}", str)
        decode_str1 = ""
        decode_str2 = ""
        for key in str_array:
            for i in range(0,26):
                if key == Baconian.first_cipher[i]:
                    decode_str1 += Baconian.alphabet[i]
                if key == Baconian.second_cipher[i]:
                    decode_str2 += Baconian.alphabet[i]

        print(decode_str1)
        print(decode_str2)



if __name__ == '__main__':
    str = input("please input string to decode:\n")
    bacon = Baconian(str)
    bacon.decode()

總結:

培根密碼:base64解碼後直接培根解密http://ctf.ssleye.com/baconian.html
Crypto2:RSA小明文攻擊,得出輸出也就是C後,使用https://xz.aliyun.com/t/6459裡面的指令碼。

MISC2:16進位制編輯器開啟,逆序答案在內。

Re1 ida 開啟搜尋字串 flag,一堆 flag 中間只有一個有參照的,就是正確的。