首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Python Base64 逆向破解:已知 key 反推 flag

     編輯:程式設計疑難解答

加密邏輯

def encode(flag):
    l1 = [chr(ord(a) - 10) for a in flag]
    l1.reverse()
    mid = ''.join(l1)
    key = base64.b64encode(mid)
    return key

key = 'YmVVJ2ReT2ZqZVVpWSY=='

逆向解密

import base64

def decode(value):
    tmp_str = base64.b64decode(value)  # 1. Base64 解碼
    lists = list(tmp_str)
    lists.reverse()                     # 2. 反轉列表
    new_list = [chr(ord(x) + 10) for x in lists]  # 3. 每字符 +10
    return ''.join(new_list)

flag = decode('YmVVJ2ReT2ZqZVVpWSY==')
print(flag)  # 輸出原始 flag

步驟解析

  1. Base64 解碼得到中間字符串。
  2. 反轉字符順序(抵消加密時的 reverse)。
  3. 每字符 ASCII 碼 +10(抵消加密時的 -10)。
  4. 拼接得原始 flag。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved