1.0 KiB
1.0 KiB
Machine Fix
The main idea finding the flag is just understanding the algorithm.
Step-1:
After I downloaded code.py
, I tried to understand the workflow here:
def convert (n):
if n == 0:
return '0'
nums = []
while n:
n, r = divmod(n, 3)
nums.append(str(r))
return ''.join(reversed(nums))
count=0
n=1
while(n<=523693181734689806809285195318):
str1=convert(n)
str2=convert(n-1)
str2='0'*(len(str1)-len(str2))+str2
for i in range(len(str1)):
if(str1[i]!=str2[i]):
count+=1
n+=1
print(count)
Step-2:
For every number n, n and n - 1 are converted to base 3 & then, the program compare the digits, the number of differences is added to total.
So I wrote a simple flag.py
script to get flag:
def flag(n):
sum = 0
while (n > 0):
sum += n
n //= 3
return sum
print(flag(523693181734689806809285195318))
On running it by python3 flag.py
Step-3:
Finally the flag becomes:
csictf{785539772602034710213927792950}