Tags: reversing
Rating:
# Phunky Python 2 - 115 Points
We stumbled across another phunky Python file. Can you find the redacted value of jkx that makes this program print True?
### Solution
###### Writeup by VoidMercy from phsst
We were given a python program shown below:
```python
import operator
jkx = 0 # REDACTED
pork = (((12 * jkx) + 44) / 4) - (2 * jkx) - 12
jkx = jkx * pork
pp = filter(lambda g: not any(g % u == 0 for u in range(2, g)), range(2, 10000))
b = reduce(operator.mul, (pp[i] ** int(str(jkx)[i]) for i in range(len(str(jkx)))))
numbequalto = 298142533459972353125216208611896260313759854634379454017626913019869030523755628601926829163490056136759291154170246269588079406415640897289723163043052735571403370823999085880254558960787830191426580931166730005416850884124181616949102806794078012758190650585958197054633549146371576221689963259346156534026838740762695201862923852711351603315111735215388452000
print (b == numbequalto)
```
We had to find the value of jkx in order to make the program print true. We start reversing what the program does.
First we had to find what b is equal to. After playing around with the functions in python's shell, we find that for each character in jkx, b is equail to pp[i] to the power of that character, all of these multiplied by each other.
Then we have to find what pp is. We simply printed pp after it is computed, and got a list of the first 1229 primes. This list will be constant every time, so we can just use this in our solution.
Then, after simplifying pork, we find that pork = jkx - 1.
Now we know what every line in this program does. We just have to find out what numbers in list pp multiplied by each other would equal to "numbequalto".
Here is my script to find this:
```python
lst = REMOVED #I removed this because it was very big :p basically it's just the list of the first 1229 primes
numbequalto = 298142533459972353125216208611896260313759854634379454017626913019869030523755628601926829163490056136759291154170246269588079406415640897289723163043052735571403370823999085880254558960787830191426580931166730005416850884124181616949102806794078012758190650585958197054633549146371576221689963259346156534026838740762695201862923852711351603315111735215388452000
print (len(lst))
#length of 1229
counter = 0
flag = "0" * 1229
flag = list(flag)
for i in lst:
counter += 1
times = 0
while (numbequalto % i == 0):
times += 1
numbequalto = numbequalto / i
if (times != 0):
print (str(i) + " " + str(counter - 1) + " " + str(times))
flag[counter - 1] = str(times)
print (numbequalto)
print ("".join(flag))
```
The result is:
```
55394379648894917577198360684718697256000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```
Because b is multiplied by pp[index] ^ number, if number is zero, this line will do nothing since b will be multiplied by 1. Therefore, we can remove all of the trailing zeroes and obtain the number: 55394379648894917577198360684718697256
Now because jkx is multiplied by pork, which is jkx - 1, we have to find the original jkx. We can solve for this by using:
jkx * (jkx - 1) = 55394379648894917577198360684718697256
jkx ^ 2 - jkx - 55394379648894917577198360684718697256 = 0
I plugged this into wolfram alpha, and obtained the flag.
## Flag
>7442740063235778328