用python闡釋工作量證明(proof of work),pythonproof
瞭解比特幣的都知道挖礦很耗電,這是因為比特幣用到了工作量證明.
工作量證明是指系統為達到某目標而設定的工作度量方法.一開始是用在網路攻防上,大大提高攻擊者的計算量,攻擊成本也就上去了.
工作量證明需要由工作者和驗證者兩方共同完成.它有兩層含義.
- 1.工作者需要完成的工作必須有一定的量,這個量由驗證者給出.
- 2.驗證者可以迅速的檢驗工作量是否達標,注意這裡的檢驗完成過程必須簡單.
舉幾個例子
- A跟B說,你給我還原這個魔方,B還原魔方需要很多時間,而A驗證卻很快,只需要看一眼就行了.
- A跟B說,你給我解這個10次方程,過程很麻煩,但是結果容易驗證.
- A跟B說,你給我把這個遊戲玩通關,B需要一定時間,而A驗證卻很快.
- RSA演算法基於一個十分簡單的數論事實:將兩個大素數相乘十分容易,但是想要對其乘積進行因式分解卻極其困難.
- ...
在電腦系統中,可以這樣設計:
驗證者給定一個隨機字串s,工作者必須找出一個數n,使得隨機字串拼上這個數n後的md5結果前面幾位都是0.
即md5(s+n)的結果符合驗證者的要求.工作者只能不停的窮舉,找出這樣一個數n.
下面上python代碼.
工作方:
#coding=utf-8from itertools import countfrom hashlib import md5msg = 'randomstring'for i in count(): hashid = md5(msg+str(i)).hexdigest() if hashid.startswith('0000'): print i,hashid break輸出39496 00001c48020e444f58a297a0785df5cf,即工作方需要md5()39496次.
而驗證方只需要拿工作方給過來的n,進行一次md5即可驗證.
即if md5(msg+str(n)).hexdigest()[:4] == '0000'.
因為md5用十六進位表示,每一位出現的機率是16.所以工作者要找到前面4位都是0平均需要16*16*16*16=65536次.
驗證者可以根據自身需要來規定前面0的個數來控制工作者的工作量.想要對方耗多點電,那就多加幾個0吧.
漢譯英:幫我把這個工作證明翻譯成英語,多謝哦
Proof of employment
This is to certify that Mr. XX has been working in XX from July 2008 till now. He is currently with XX department as a XX. His job responsibilities include interviewing, editing, recording, etc. He is responsible and reliable. His performance is highly appraised.
最高分幾個簽證時的法語翻譯模板
1. Identity card
2. bank deposits for passport
3. Parental income proof: proof of work and wages account for at least six months of payroll records
4. The burden on parents signing children in the law during the cost of that
1. Carte d'identité
2. dépôts bancaires du passeport
3. Bulletin de salaire des parents + feuilles de paie des 6 derniers mois de travail (des parents)
4. La charge des parents prouvant que les enfants sont sous la loi