Rating: 3.0

![](https://images.sandcat.nl/index.php?action=view&id=746)

The challenge provides us with a python script bells.py. Running this script it asks for a number and tells us the outcome. Looking at the script it will display "**Nice you got it, your flag is the value you initally got in the form 'uiuctf{NUMBER_YOU_GOT}'**" If the correct number is entered.
There's basically just a bunch of calculations and conversions going on with a set final string which is expected 'Lmao'. It is now possible to work back from that to get to the number of bells Tom Nook has;

Tools used:
* windows calculator (with scientific notations enabled)
* http://www.asciitable.com/

Read the code and comments from bottom to top, as I started with the expected outcome 'Lmao' and worked my way back to what *guess* is expected.
Inbetween every processing step I have included the content(s) of guess.

```
print('Input a Number Below to guess how many bells Tom Nook has :)')
guess = None
try:
guess = int(input())
except:
print("No silly that is wrong, you need a number.")
exit()
try:
# guess = 1293869277 -> flag: uiuctf{1293869277}
# -2410619
for tax3 in range(0,1234):
guess -= 1337 + tax3

# guess = 1291458658
guess = str(hex(int(guess)))[2:] # convert the integer to a hexadecimal string

# guess = '4CFA1862'
# split the string in two and put the last 4 character before the first 4 characters
guess = str(guess[4:8]) + str(guess[0:4])

# guess = '18624CFA'
guess = int(guess,16) # interpret guess as hexadecimal thus converting to an integer

# guess = 409095418
for tax4 in range(18,30,2):
guess = int((str(hex(guess)[2:])[::-1]),16) - tax4 * 1000 # magic
# final step (28) to get to 457253818 to determine logic:
# -(28 * 1000) guess = 457281818 :add tax
# convert that to hex: 1B41911A :to hex
# reverse that hexadecimal string: A11914B1 :reverse
# which is 2702775473 :to dec
#
# reversing the remaining steps:
# add tax to hex reverse to dec
# 26: 2702775473 + 26000 = 2702775473 -> A1197A41 -> 14A7911A -> 346525978
# 24: 346525978 + 24000 = 346549978 -> 14A7EEDA -> ADEE7A41 -> 2918087233
# 22: 2918087233 + 22000 = 2918109233 -> ADEED031 -> 130DEEDA -> 319680218
# 20: 319680218 + 20000 = 319700218 -> 130E3CFA -> AFC3E031 -> 2948849713
# 18: 2948849713 + 18000 = 2948849713 -> AFC42681 -> 18624CFA -> 409095418

# guess = 457253818
# -5970000
for tax5 in range(0,1000,5):
for tax4 in range(10,40,10):
guess -= tax5 * tax4

# guess = 451283818
guess = str(hex(guess)[2:]) # convert to hexadecimal

# guess = '1AE60B6A'
# split the string per 2 characters and convert them from hex into a decimal array
guess = [int(guess[i:i+2],16) for i in range(0,len(guess),2)]

# guess = [26, 230, 11, 106]
# sorting the caculations per array element and having them line by line:
guess[0] *= 3 # *3
guess[0] += int((ord('j') - ord('J')) / (ord('E') - ord('e'))) # -1
guess[0] += int((ord('g') - ord('G')) / (ord('z') - ord('Z')) * ord('c') - ord('a')) # +2

guess[1] /= 2 # /2
guess[1] -= 18 # -18

guess[2] += ord('b') # +98

guess[3] -= 30 # -30

# guess = [79, 97, 109, 76]
guess = [hex(int(g)) for g in guess][::-1] # reverse the array and convert from int to hex

# guess = ['4C','6D','61','4F']
guess[3] = hex(int(guess[3],16) + 32) # +32 for guess[3]

# guess = ['4C','6D','61','6F'] ('L','m','a','o')
final = ''
for i in range(len(guess)):
final += chr(int(guess[i],16)) # convert the array entries from hex to character and form them into a string

if final == 'Lmao':
print("Nice you got it, your flag is the value you initally got in the form 'uiuctf{NUMBER_YOU_GOT}'")
else:
print("Good try but your ending value was " + final + " try again <3")
print("\n")
except:
print("Your guess was so wrong you broke the guessing machine. Good try, but try again <3")

```