الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

أريد التحويل من python إلى java .

بدأه هدف الشمالي في 8 أكتوبر 2014 · 0 رد · 912 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1
هنا ثلاث أكواد أريد تحويلها للجافا
الكود الأول وهو أهمها :
import hashlib, struct
ver = 2
prev_block = "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"
mrkl_root = "871714dcbae6c8193a2bb9b2a69fe1c0440399f38d94b3a0f1b447275a29978a"
time_ = 0x53058b35 # 2014-02-20 04:57:25
bits = 0x19015f53
# https://en.bitcoin.it/wiki/Difficulty
exp = bits >> 24
mant = bits & 0xffffff
target_hexstr = '%064x' % (mant * (1<<(8*(exp - 3))))
target_str = target_hexstr.decode('hex')
nonce = 0
while nonce < 0x100000000:
   header = ( struct.pack("<L", ver) + prev_block.decode('hex')[::-1] +
         mrkl_root.decode('hex')[::-1] + struct.pack("<LLL", time_, bits, nonce))
   hash = hashlib.sha256(hashlib.sha256(header).digest()).digest()
   print nonce, hash[::-1].encode('hex')
   if hash[::-1] < target_str:
       print 'success'
       break
   nonce += 1
الكود الثاني :
 
import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("us1.ghash.io", 3333))

sock.send("""{"id": 1, "method": "mining.subscribe", "params": []}\n""")
print sock.recv(4000)

sock.send("""{"params": ["kens_1", "password"], "id": 2, "method": "mining.authorize"}\n""")
print sock.recv(4000)
الكود الثالث :
 
import hashlib# Hash pairs of items recursively until a single value is obtaineddef merkle(hashList):   if len(hashList) == 1:       return hashList[0]   newHashList = []   # Process pairs. For odd length, the last is skipped   for i in range(0, len(hashList)-1, 2):       newHashList.append(hash2(hashList, hashList[i+1]))   if len(hashList) % 2 == 1: # odd, hash last item twice       newHashList.append(hash2(hashList[-1], hashList[-1]))   return merkle(newHashList)def hash2(a, b):   # Reverse inputs before and after hashing   # due to big-endian / little-endian nonsense   a1 = a.decode('hex')[::-1]   b1 = b.decode('hex')[::-1]   h = hashlib.sha256(hashlib.sha256(a1+b1).digest()).digest()   return h[::-1].encode('hex')# https://blockexplorer.com/rawblock/0000000000000000e067a478024addfecdc93628978aa52d91fabd4292982a50txHashes = [ "00baf6626abc2df808da36a518c69f09b0d2ed0a79421ccfde4f559d2e42128b", "91c5e9f288437262f218c60f986e8bc10fb35ab3b9f6de477ff0eb554da89dea",] print merkle(txHashes)

مواضيع مشابهة