Score:1

Finding Inverse Modulo

jp flag

I'm working on a challenge like this:

def weird_func(FLAG)
    enc_flag = [(a + b*i) % n for i in FLAG]
    return bytes(enc_flag).hex()

Although I know the FLAG prefix which is flag{, without knowing a,b and n, I find it hard to calculate the whole FLAG. Only enc_flag is given in hex. I tried to brute-force but it seems like n is too large, or maybe I'm wrong. Can anyone help me step-by-step with this problem?

DannyNiu avatar
vu flag
Hint: $a + b \cdot i$ is a linear expression with 2 variables, with 2 of them, you have a system of equations enough to solve it. You may be already familiar with it in real numbers, now you just do it modulo $n$. (If $n$ is a prime, then it's a field just like real numbers).
poncho avatar
my flag
What control do you have over FLAG? Can you arbitrarily set the prefix? Or, do you know the prefix but can't set it?
LilLee avatar
jp flag
@poncho well I just guess that the FLAG will be in the same format as before, so I'm assuming that I know the first 5 characters, `flag{`. I'm not familiar with this so finding `n` is tough to me.
fgrieu avatar
ng flag
@LilLee: assuming your code needs only an additional `:` to be executable with `FLAG` on the tune of `b"flag{"`, we can find a very likely maximum value for `n`, and it's not large. And you (not us) can find a minimum, further narrowing down the values of `n`. Then the first hint applies.
in flag
Hint: In python, given `c = (b * i) % n`, then `b_inverse = pow(b, n - 2, n)`, and `i == (b_inverse * c) % n`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.