分段解密

题目:

import sys

def abc(First):  
    First = c_uint32(First)
    return First


def enflag(i, j):
    a = 32
    tt = 0x9e3779b9
    b = [0,0]
    First = abc(i[0])
    Second = abc(i[1])
    add = abc(0)
    add=add.value
    while(a>0):
        add += tt
        First.value += ( Second.value << 4 ) + j[0] ^ Second.value + add ^ ( Second.value >> 5 ) + j[1]
        Second.value += ( First.value << 4 ) + j[2] ^ First.value + add ^ ( First.value >> 5 ) + j[3]
        a = a - 1
    b[0] = First.value
    b[1] = Second.value
    return b
    

def str_encoding(ecryptText, PK):
    List = []
    ecryptText += (8 - len(ecryptText) % 8) * chr(0)
    for m in range(len(ecryptText)/8):
        p = 0
        q = 0
        for n in range(4):
            p+= ord(ecryptText[m*8+n]) << (4-n-1)*8
            q+= ord(ecryptText[m*8+n+4]) << (4-n-1)*8
        List.append(enflag([p,q],PK))
    return List

if __name__ == "__main__":
    flag = xxxx
    PK = [141,262,339,425]
    crypto = str_encoding(flag,PK)
    print(crypto)
#[[3202805436L, 509716930L], [3140667873L, 1667141091L], [3173275598L, 2248305098L], [709283154L, 3416762332L]]

思路:
慢慢逆向ba
script:

from ctypes import c_uint32


def abc(First):
    First = c_uint32(First)
    return First


# def str_encoding(ecryptText):
#     List = []
#     ecryptText += (8 - len(ecryptText) % 8) * chr(0)
#     #print(ecryptText)
#     #print(len(ecryptText))
#     print(int(len(ecryptText)/8))
#     for m in range(int(len(ecryptText)/8)):
#         p = 0
#         q = 0
#         for n in range(4):
#             p+= ord(ecryptText[m*8+n]) << (4-n-1)*8
#             q+= ord(ecryptText[m*8+n+4]) << (4-n-1)*8
#         #print(p,q)
#         List.append([p, q])
#     return List
# s="flag{123266666666666}"
# #print(len(s))
# #print(len(s)/8)
# #print(len(s) % 8)
# list = str_encoding(s)
# print(list)


def cry(s):
    flag = [0] * len(s) * 8
    print(flag)
    print(len(s))
    for i in range(len(s)):
        p = s[i][0]
        q = s[i][1]
        print(p, q)
        for j in range(4):
            print(i * 8 + j)
            flag[i * 8 + j] = chr(p >> (4 - j - 1) * 8 & 0xFF)
            flag[i * 8 + j + 4] = chr(q >> (4 - j - 1) * 8 & 0xFF)
        print(flag)
        flagg = ""
    for z in range(len(flag)):
        flagg += str(flag[z])
    print("flag>>>", flagg)
    return flagg


# cry(list)


# def enflag(i, j):
#     a = 32
#     tt = 0x9e3779b9
#     #print("tt>>>",int(tt))
#     b = [0,0]
#     First = abc(int(i[0]))
#     #print("First>>>",First.value)
#     Second = abc(int(i[1]))
#     #print("Second>>>",Second.value)
#     add = abc(0)
#     #print("add>>>",add)
#     add=add.value
#     #print("add>>>",add)
#     while(a>0):
#         add += tt
#         print("add>>>",add)
#         First.value += ( Second.value << 4 ) + j[0] ^ Second.value + add ^ ( Second.value >> 5 ) + j[1]
#         print("First>>>",First.value)
#         Second.value += ( First.value << 4 ) + j[2] ^ First.value + add ^ ( First.value >> 5 ) + j[3]
#         print("Second>>>",Second.value)
#         a = a - 1
#     b[0] = First.value
#     b[1] = Second.value
#     return b

PK = [141, 262, 339, 425]
# ss = enflag(list[0],PK)
# print("list>>>",list[0])
# print("ss>>>",ss)


def cryy(i, j):
    a = 32
    tt = 0x9E3779B9
    b = [0, 0]
    First = abc(i[0])
    # print("First>>>",First)
    Second = abc(i[1])
    # print("Second>>>",Second)
    add = abc(84941944608)
    add = add.value
    while a > 0:
        Second.value -= (
            (First.value << 4) + j[2] ^ First.value + add ^ (First.value >> 5) + j[3]
        )
        First.value -= (
            (Second.value << 4) + j[0] ^ Second.value + add ^ (Second.value >> 5) + j[1]
        )
        add -= tt
        a = a - 1
    b[0] = First.value
    b[1] = Second.value
    return b


# sss = cryy(ss, PK)
# print("sss>>>", sss)

crypto = [
    [3202805436, 509716930],
    [3140667873, 1667141091],
    [3173275598, 2248305098],
    [709283154, 3416762332],
]
c1 = []
for i in range(len(crypto)):
    c1.append(cryy(crypto[i], PK))
print("c1>>>", c1)
c = cry(c1)
c = c.strip("\x00")
print(c[::-1])
# flag{1UHSUW_IJNIL_1s_galf}

posted @ 2025-05-12 20:00  lethe311  阅读(21)  评论(0)    收藏  举报