Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python to explain workload proof

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to use python to explain the workload proof, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Anyone who knows Bitcoin knows that mining consumes electricity because Bitcoin uses proof of workload.

Workload proof refers to the work measurement set by the system to achieve a goal. At first, it is used in network attack and defense, which greatly increases the amount of computation of the attacker, and the attack cost goes up.

The proof of workload needs to be done jointly by both the worker and the verifier. It has two meanings.

1. There must be a certain amount of work to be done by the worker, which is given by the verifier.

two。 The verifier can quickly check whether the workload is up to standard. Note that the inspection process here must be simple.

Give me a few examples.

A said to B, you give me to restore this Rubik's cube, B restore Rubik's cube will take a lot of time, but A verification is very fast, just take a look at it.

A told B that it was troublesome for you to solve this equation of degree 10 for me, but the result was easy to verify.

A said to B, you give me this game to play customs clearance, B will take some time, but A verification is very fast.

The RSA algorithm is based on a very simple number theory fact: it is very easy to multiply two large primes, but it is extremely difficult to decompose their products.

...

In a computer system, it can be designed as follows:

Given a random string s by the verifier, the worker must find a number n so that the first few digits of the md5 result after the random string is spelled with this number n are all 0.

That is to say, the result of md5 (soundn) meets the requirements of the verifier. Workers can only keep exhaustive efforts to find out such a number n.

The following is the python code.

Working side:

# 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 iJH Hashid break

Output 39496 00001c48020e444f58a297a0785df5cf, that is, the worker needs md5 () 39496 times.

On the other hand, the verifier only needs to take the n given by the worker and do a md5 to verify it.

That is, if md5 (msg+str (n)). Hexdigest () [: 4] = = '0000000.

Because md5 is represented in hexadecimal, the probability of each bit appearing is 16. 5%. So it takes an average of 16,16,16,65536 times for workers to find that the first four digits are all zero.

The verifier can control the workload of workers by setting the number of the first zeros according to their own needs. If you want the other party to consume more electricity, add a few more zeros.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report