VHChineseChess v1.00
VHChineseChess v1.00
Play against the best Chinese Chess AI Engineer with 5 levels of difficult in HD graphics or improve your ending skill by solving 280+ built-in postures.
Link: VHChineseChess on Google Play market
I took part in a lot of CTF before but almost none of the solutions to these problems was algorithm related. This year, Plaid CTF 2013 has an interesting problem that’s mostly numerical ![]()
The problem:
#!/usr/bin/python -u import sys import struct import os import hashlib def strtonum(s): ret = 0 for h in s: ret *= 256 ret |= ord(h) return ret def numtostr(s, l): ret = "" for i in range(0, l): ret = chr(s&0xFF) + ret s >>= 8 return ret port = 1234 # RSA modulus(factor me) N = 0xc3542f8b7b2c9f083912972d8d07312fce5cf549ae8b25e97a691d35a72f953dad939811e1ec4d46fafd5db3034fee45c5f700a57915a67238925361b3ea7ae58e392b92d13af8e1604298794f640db466642933825813bf329b228f773a5137a625bd23ffa1d8bb7ca9b49d6235a0e4f839226f14a9e7a42fa4f7d530725803 print "WE ONLY RUN SIGNED CODE, DO YOU HAVE SIGNED CODE?" l = struct.unpack("I", sys.stdin.read(4))[0] hashee = sys.stdin.read(0x80) msg = numtostr(pow(strtonum(hashee), 3, N), 0x80) code = sys.stdin.read(l) if msg[0:4] != "\x00\x01\xFF\xFF": print "BAD PADDING" sys.exit(0) h = hashlib.sha1(code).digest() if msg[len(msg)-len(h):] != h: print "BAD HASH" sys.exit(0) eval(code) |
We need to build a correct signature to evaluate our code and continue. The signature is a 128-char string which procedure a valid real signature thas is of the format:
\x00\x01\xFF\xFF<104 free byte><20 byte sha hash of code>
At first, I tried to factor N by Maple but it ran so long that I think that N is prime, and so the problem seems to be a cubic residual one, but after reading some paper and done the implement, I realized that N is not a prime, because it doesn’t satisfy Fermat’s little theorem.
After some more time playing with it, I found that the problem is not that hard. N is just so big that we don’t need to care about it
First, we need to find a number suffix which will procedure the <20 byte sha hash of code> part, which can be done by searching digit by digit from the LSB (256^0) to MSB (256^19).
hn = strtonum(h) # hn is a number representation of the sha hash rsuf = 0 rpow = 1 print 'Find suf for ',hn nsuf = 22 for i in xrange(nsuf): jFound = None for j in xrange(256): n = pow(rsuf + rpow*j,3); if (n-hn) % (256*rpow) == 0: jFound=j break if not (jFound is None): rsuf +=rpow * jFound rpow*=256; else: print 'not found' raise "Cannot find suffix"; rsuf%=pow(256,nsuf) print 'Done, found: ',rsuf |
After that, we need to find a number that its 3rd power match the format x00\x01\xFF\xFF<124 byte>, and then replace its 20 LSB by the suffix we’ve found.
rmin = strtonum('\x00\x01\xFF\xFF'+('\x00'*(124-len(h)))+h) z=find_invpow(rmin,3) r=(z+pow(256,nsuf)-(z%pow(256,nsuf)))+(rsuf) # add pow(256,nsuf) just to make sure that r is larger than z. |
The final code’s below, note that the problem is still solvable even if we got a smaller N or a bigger real signature just by some small changes, but it’s left for you
import sys import struct import os import hashlib import socket def strtonum(s): ret = 0 for h in s: ret *= 256 ret |= ord(h) return ret def numtostr(s, l): ret = "" for i in range(0, l): ret = chr(s&0xFF) + ret s >>= 8 return ret def hexV(s): return str(len(s))+"#"+(":".join("{0:x}".format(ord(c)) for c in s)) N = 0xc3542f8b7b2c9f083912972d8d07312fce5cf549ae8b25e97a691d35a72f953dad939811e1ec4d46fafd5db3034fee45c5f700a57915a67238925361b3ea7ae58e392b92d13af8e1604298794f640db466642933825813bf329b228f773a5137a625bd23ffa1d8bb7ca9b49d6235a0e4f839226f14a9e7a42fa4f7d530725803 code = """[x for x in (1).__class__.__base__.__subclasses__() if x.__name__ == 'catch_warnings'][0]()._module.__builtins__['print'](open(os.path.dirname(os.path.realpath(__file__))+'/key').read(1024)) """ def find_invpow(x,n): """Finds the integer component of the n'th root of x, an integer such that y ** n <= x < (y + 1) ** n. """ high = 1 while high ** n < x: high *= 2 low = high/2 while low <= high: mid = (low + high) // 2 if mid**n < x: low = mid +1 else: high = mid -1 return low h = ("\x00"*2)+hashlib.sha1(code).digest() print 'Hash: ',hexV(h),'\n' hn = strtonum(h) rsuf = 0 rpow = 1 print 'Find suf for ',hn nsuf = 22 for i in xrange(nsuf): jFound = None for j in xrange(256): n = pow(rsuf + rpow*j,3); if (n-hn) % (256*rpow) == 0: jFound=j break if not (jFound is None): rsuf +=rpow * jFound rpow*=256; else: print 'not found' raise "Cannot find suffix"; rsuf%=pow(256,nsuf) print 'Done, found: ',rsuf print 'Test: rsuf^3-hn % (256^`nsuf`) = ',(pow(rsuf,3)-hn)%pow(256,nsuf),'\n' rmin = strtonum('\x00\x01\xFF\xFF'+('\x00'*(124-len(h)))+h) z=find_invpow(rmin,3) print hexV(numtostr(pow(z,3),0x80)) r=(z+pow(256,nsuf)-(z%pow(256,nsuf))) r=(z+pow(256,nsuf)-(z%pow(256,nsuf)))+(rsuf) print 'Test: r^3-hn % (256^`nsuf`) = ',(pow(r,3)-hn)%pow(256,nsuf),'\n' client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect(('54.234.73.81', 1234)) data = client_socket.recv(128) print data mess = struct.pack("I",len(code)) if len(mess)!=4: System.exit() mess +=numtostr(r,0x80) mess +=code f=open("/tmp/f","wb") f.write(mess) f.close() try : client_socket.sendall(mess) except socket.error: print 'Send failed' sys.exit() print 'sent' data = client_socket.recv(128) client_socket.close() print 'RECV: ',data |
VHChineseChess v1.00
Play against the best Chinese Chess AI Engineer with 5 levels of difficult in HD graphics or improve your ending skill by solving 280+ built-in postures.
Link: VHChineseChess on Google Play market
Chào các bạn.
Cũng lâu rồi mình không viết bài nào ở đây, và cũng lâu lắm rồi mình không cập nhật nội dung thư viện, còn VHDict thì dường như đã chết.
Một phần là vì giờ mình không có thời gian nhiều, một phần nữa cũng vì mình thấy nhu cầu sử dụng ebook offline không được như xưa nữa… Giờ đây 3g đã phổ biến hơn, giá cước cũng ngày càng giảm đi… Thêm vào đó là sự bùng nổ của các công nghệ đám mây, kỉ nguyên Web 3.0 mang lại tính tương tác và tiện lợi cao cho tất cả mọi người (VD: wattpad).
Cũng vì những lý do như trên, VHDict cũng không được phát triển nữa (một lý do quan trọng khác là vì mình đã hoàn toàn mất source code của chương trình (từ lần mất lap trước)).
Tuy nhiên, có vẻ như vẫn còn nhiều người muốn sử dụng thư viện của mình
Nên mình sẽ gắng cập nhật sớm nhất có thể (có lẽ là vào đầu kì nghỉ hè).
Cám ơn các bạn đã ủng hộ
New features:
- Fix some logical bugs in puzzle games/Sửa một số lỗi logic ở phần cờ thế.
- Added some new pop-up/Thêm một số popup.
Link: Download here
Read more: this entry.
Cũng lâu lắm rồi mình không làm gì cả, quả thực mình chẳng thấy hứng thú làm gì hết, VHDict, EBooks, mình đều chán cả…
Chẳng hiểu sao giờ bỗng nhiên lại muốn làm cái này, đây là phần mềm chơi cờ tướng dành cho Kindle, mình có thực hiện chức năng lựa chọn và di chuyển quân cờ dành riêng cho bàn phím cứng (sẽ nhanh hơn là di chuyển ô trên kindle), còn về game thì ngoài đấu bình thường với máy (5 cấp độ) còn có chức năng chơi cờ thế nữa.
Hello,
This is a Chinese Chess implement for your Kindle, it including a multi-level (5) AI to be played with you any where and any time you want, or you can try solving short Chess Puzzle (but you may need very long time in some case i think:D). I also built a piece-controling function which is the best method (just my opinion) to control a chess board with the kindle.
Trước khi sử dụng chương trình này, bạn phải cài đặt devkey của mình trên Kindle của bạn (chỉ cần cài lần đầu).
Đầu tiên các bạn phải up lên 3.1 và jailbreak, nếu chưa jailbreak thì các bạn jailbreak bằng cách tải file này về, giải nén copy file .bin thích hợp vào thẻ nhớ, ngắt kết nối rồi trên kindle ấn menu, chọn setting, ấn menu, chọn update your kindle.
Sau khi jailbreak xong, tải http://www.vhn.vn/Link:Kindle:vanhoadevkey, giải nén, copy file update_*_install.bin thích hợp vào thư mục gốc thẻ nhớ máy bạn (thư mục chứa documents), mở
Before using this application, you have to update your kindle to the latest firmware and jailbreak it, consider this link for more information about jailbreak. After that, you have to install my devkey on your kindle (only once). First, download http://www.vhn.vn/Link:Kindle:vanhoadevkey, copy update_*_install.bin for your device into the root folder of your sdcard (the one which has ‘documents’,..), add update_vanhoadevkeys to
Update 2011.05.05:
Download: http://www.vhn.vn/Link:KindleChineseChess-latest, copy vào thư mục documents/copy to your documents folder.
Mình vừa cập nhật phiên bản mới cho VHDict, có 2 thay đổi:
1. Thêm dấu * trước những từ có dữ liệu phát âm
2. (hi vọng) fix lỗi crash khi chuyển trang trên máy cảm ứng.
Tải tại đây.
Cám ơn các bạn đã ủng hộ chương trình
Giá như lúc này không còn là hôm nay, vĩnh viễn không còn khái niệm thời gian.
Smile more, cry more….