-2
파이썬에서 작성할 수 있도록이 코드에서 정확히 무슨 일이 일어나는지 설명 할 수 있습니까? 내가 바로이 부분 때문에 나중에 사양을 작성 같은 C를 따라야합니다 Bep33을위한 파이썬 꽃 필터로 구현됩니다 내가파이썬에서 작성된 코드를 변환하는 방법
import hashlib
import socket
import struct
class blommy(object):
def __init__(self):
self.bitarray= [0]*2048
def hashes(self,ip):
#convert decimal dotted quad string to long integer"
intip= struct.unpack('>L',socket.inet_aton(ip))[0] #>converting stringt to int
index = [0, 1]
hbyte = hashlib.sha1(intip) # # #sha1 doesnt accept int ? what needs to be done?
index[0] = ord(hbyte[0])| ord(hbyte[1])<< 8
index[1] = ord(hbyte[2])| ord(hbyte[3])<< 8
# how do i shift the bits?
아래 주석을 참조 파이썬로 변환하려고
//fixed parameters
k = 2
m = 256*8
//the filter
byte[m/8] bloom ##
function insertIP(byte[] ip) {
byte[20] hash = sha1(ip)
int index1 = hash[0] | hash[1] << 8 # how to in python?
int index2 = hash[2] | hash[3] << 8
// truncate index to m (11 bits required)
index1 %= m ## ?
index2 %= m ## ?
// set bits at index1 and index2
bloom[index1/8] |= 0x01 << index1 % 8 ## ??
bloom[index2/8] |= 0x01 << index2 % 8 ## ??
}
// insert IP 192.168.1.1 into the filter:
insertIP(byte[4] {192,168,1,1})
토런트 DHT 비트
거기에 C# 및 JavaScript 태그는 무엇입니까? – alexn
@alexn probbaly 원래 코드는 C#가 아니라 C#입니다. 배열 형식의 구문 (비록 실제 C#도 아니지만) – wRAR
원본 코드가 C#, C 등의 문제가 아니더라도 질문은 내가 DHT 용이라고 언급 한 논리를 이해하는 것이 었습니다. – Shazib