You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

密码学挑战逆向求助:如何从解密逻辑还原加密函数?

Reversing the Cryptography Challenge: Building the Encryption Function

Hey there! Let's walk through how to build the encryption function that generates that hint array you worked with. You already nailed the decryption by taking the difference between consecutive elements—so reversing this is just about flipping that operation on its head.

Understanding the Encryption Logic

First, let's formalize the relationship between the plaintext and the array x:

  • The initial value x[0] = 0 is a fixed starting point.
  • Each subsequent element in x is the cumulative sum of the ASCII values of the plaintext characters up to that point:
    • x[1] = ord(plaintext[0]) (since x[1] - x[0] = ord(plaintext[0]))
    • x[2] = x[1] + ord(plaintext[1]) (which lines up with x[2] - x[1] = ord(plaintext[1]))
    • For any index i >= 1, x[i] = x[i-1] + ord(plaintext[i-1])

Implementing the Encryption Function

Here's a straightforward Python function that takes a plaintext string and returns the corresponding array x:

def encrypt(plaintext):
    x = [0]  # Start with the fixed initial value
    current_sum = 0
    for char in plaintext:
        current_sum += ord(char)
        x.append(current_sum)
    return x

# Test it with the flag you decrypted
flag = "gigem{n3v3r_evv3r_r01l_yer0wn_cryptoo00oo}"
encrypted_array = encrypt(flag)
print(encrypted_array)

Run this, and you'll see it outputs exactly the hint array from your challenge—this confirms we've got the logic spot-on!

A Quick Note on This Encryption Method

This is a super basic cumulative sum (prefix sum) encryption scheme. It's not secure at all (as you saw, decrypting is trivial by taking adjacent differences), but it's a great example of how reversing simple crypto functions just requires mapping the decryption steps backwards.

内容的提问来源于stack exchange,提问作者g0osebumps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 22:57:31