-2
誰かがこのコードで何が起こっているのかを説明できるので、私はPythonで書くことができます。私はPythonで書かれたコードを変換する方法
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?
以下のコメントを参照してくださいPythonのためにそれを変換しようとしていますまさにこの部分にそう後で仕様が書かれた同じcはBep33ビットトレントDHTのためのPythonのブルームフィルタに
//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})
を実施しますに従う必要があり
C#タグとJavaScriptタグは何ですか? – alexn
@alexn probbaly元のコードはC#ではなく、Cです。配列型の構文(実際のC#ではありませんが) – wRAR
元のコードがc#、cなどにあっても問題はありません。 – Shazib