我可以帮助您进行翻译。以下是关于it技术的内容:
我正在尝试打印出当前用于解密的跳数。
编辑TorHop。
我正在尝试转换以下输出:
decrypt : <torfuncs.TorHop instance at 0x7f44babb8440>
把它转换成更易读的格式,结果应该是一个字符串数组。我已经定义了__str__
和__repr__
,但即使这样,我仍然得到上面的结果。我做错了什么?
class TorCircuit():
def __init__(self, sock, circid):
self.hops = []
self.circId = circid
self.socket = sock
self.tempX = 0
self.packetSendCount = 0
self.cookie = []
def __str__(self, hop):
return 'hop #%d' % self.hops
def __repr__(self, hop):
return 'hop #%d' % self.hops
def decrypt(self, relayCell):
for hop in self.hops:
print "decrypt :", str(hop)
relayCell = hop.decrypt(relayCell)
if relayCell[1]==0 and relayCell[2]==0:
return relayCell
return relayCell
我正在尝试打印出当前用于解密的跳数。
编辑TorHop。
class TorHop:
def __str__(self):
return 'hop #' % self.hop
def __repr__(self):
return 'hop #' % self.hop
def __init__(self, KH, Df, Db, Kf, Kb):
self.KH = KH
self.Df = Df
self.Db = Db
self.Kf = Kf
self.Kb = Kb
self.fwdSha = SHA.new()
self.fwdSha.update(Df)
self.bwdSha = SHA.new()
self.bwdSha.update(Db)
ctr = Counter.new(128,initial_value=0)
self.fwdCipher = AES.new(Kf, AES.MODE_CTR, counter=ctr)
ctr = Counter.new(128,initial_value=0)
self.bwdCipher = AES.new(Kb, AES.MODE_CTR, counter=ctr)
def encrypt(self, data):
return self.fwdCipher.encrypt(data)
def decrypt(self, data):
return self.bwdCipher.decrypt(data)
通过这个,我现在获得:
AttributeError: TorHop instance has no attribute 'hops'
self.hop
而不是self.hops
。另一个问题是你试图使用%d
来打印一个看起来像列表的东西,但这会失败。 - TheSoundDefenseTorHop
类中添加__str__
和__repr__
的定义,而不是在TorCircuit
类中。 - Mark Dickinson