Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import os
- import sys
- import time
- import socket
- import hashlib
- import re
- import random
- host = "chall.ctf.bamboofox.tw"
- port = 10369
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((host, port))
- print('connect success')
- def pow_solver(prefix, difficulty):
- zeros = '0' * difficulty
- def is_valid(digest):
- if sys.version_info.major == 2:
- digest = [ord(i) for i in digest]
- bits = ''.join(bin(i)[2:].zfill(8) for i in digest)
- return bits[:difficulty] == zeros
- i = 0
- while True:
- i += 1
- s = prefix + str(i)
- if is_valid(hashlib.sha256(s.encode()).digest()):
- return i
- def main():
- print('main start')
- question = s.recv(4096)
- question = question.decode('ascii')
- print(question)
- question = question[58:74]
- print(question)
- ans = pow_solver(question, 20)
- print(str(ans) + '\n')
- s.send(bytes(str(ans) + '\n', 'ascii'))
- _ = s.recv(4096)
- print(_.decode('utf-8'))
- s.send(bytes('\n', 'utf-8'))
- with open('edges.txt', 'w') as f:
- while True:
- _ = s.recv(4096)
- if len(_) == 0:
- break
- content = _.decode('ascii')
- # print(content)
- content = re.sub("[^\d\s]", "", content)
- f.write(content)
- if _.decode('ascii').find("Enter") != -1:
- break;
- os.system("./solve < edges.txt > ans.txt")
- with open("ans.txt", "r") as f:
- ans = f.readlines();
- print(ans, len(ans))
- ans = ' '.join([x.strip() for x in ans])
- print(ans)
- s.send(bytes(str(ans) + '\n', 'ascii'))
- res = s.recv(1024)
- print(res.decode('utf-8'))
- # os.system("./solve")
- main()
Advertisement
Add Comment
Please, Sign In to add comment