- Much progress made. However, still an empty encrypted term.
This commit is contained in:
parent
7637d8a263
commit
4a638edb72
@ -6,40 +6,46 @@
|
|||||||
#
|
#
|
||||||
firstone = True
|
firstone = True
|
||||||
|
|
||||||
class Atomic(list):
|
class Atomic(object):
|
||||||
def __init__ (self,l,type=""):
|
def __init__ (self,type,s,optprime=""):
|
||||||
list.__init__(self,l)
|
|
||||||
self.type = type
|
self.type = type
|
||||||
|
self.str = s + optprime
|
||||||
|
|
||||||
def getType(self):
|
|
||||||
return self.type
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "".join(self)
|
return self.str
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Constant<" + str(self) + ">"
|
return str(self)
|
||||||
|
|
||||||
|
class Variable(Atomic):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TypedConstant(Atomic):
|
||||||
|
pass
|
||||||
|
|
||||||
class Special(Atomic):
|
class Special(Atomic):
|
||||||
def __init__ (self,x):
|
def __init__ (self,x):
|
||||||
Atomic.__init__(self,[x],"special")
|
Atomic.__init__(self, "special", x)
|
||||||
|
|
||||||
class Message(list):
|
class Message(list):
|
||||||
def __str__(self):
|
|
||||||
#return "".join(self)
|
|
||||||
res = ""
|
|
||||||
for s in self:
|
|
||||||
if res != "":
|
|
||||||
res += ","
|
|
||||||
res += str(s)
|
|
||||||
return res
|
|
||||||
|
|
||||||
def subType(self):
|
def subType(self):
|
||||||
return "(generic)"
|
return "(generic)"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
if self[0] == "crypt":
|
||||||
|
return "{" + str(self[2]) + "}" + str(self[1]) + " "
|
||||||
|
else:
|
||||||
|
res = ""
|
||||||
|
for s in self:
|
||||||
|
if res != "":
|
||||||
|
res += ","
|
||||||
|
res += str(s)
|
||||||
|
return res
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Message" + self.subType() + "<" + str(self) + ">"
|
return "Message" + self.subType() + "<" + str(self) + ">"
|
||||||
|
|
||||||
|
|
||||||
class MsgList(list):
|
class MsgList(list):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Msglist<" + list.__repr__(self) + ">"
|
return "Msglist<" + list.__repr__(self) + ">"
|
||||||
|
@ -57,25 +57,37 @@ def ruleParser ():
|
|||||||
ConstF = Literal("c(ni,ni)")
|
ConstF = Literal("c(ni,ni)")
|
||||||
Const << Or ([ Constant, ConstC, ConstF ])
|
Const << Or ([ Constant, ConstC, ConstF ])
|
||||||
|
|
||||||
|
# Optional prime
|
||||||
|
def optprimeaction(s,l,t):
|
||||||
|
if len(t) == 0:
|
||||||
|
return [ "" ]
|
||||||
|
else:
|
||||||
|
return t
|
||||||
|
optprime = Optional(Literal("'"))
|
||||||
|
optprime.setParseAction(optprimeaction)
|
||||||
|
|
||||||
# Two versions
|
# Two versions
|
||||||
Variable = Word("x",Alfabet)
|
|
||||||
if typedversion:
|
if typedversion:
|
||||||
Variable = TypeInfo + lbr + Variable + rbr
|
Variable = Word("x",Alfabet)
|
||||||
|
Variable = TypeInfo + lbr + Variable + rbr + optprime
|
||||||
# Optional prime
|
Variable.setParseAction(lambda s,l,t: [
|
||||||
optprime = Optional(Literal("'"))
|
If.Variable(t[0],t[1],t[2]) ])
|
||||||
|
else:
|
||||||
|
Variable = Word("x",Alfabet) + optprime
|
||||||
|
Variable.setParseAction(lambda s,l,t: [
|
||||||
|
If.Variable("untyped",t[0],t[1]) ])
|
||||||
|
|
||||||
# Atomic
|
# Atomic
|
||||||
## DEVIANT : below there is an optprime after the atom. This
|
## DEVIANT : below there is an optprime after the atom. This
|
||||||
## is not in the BNF.
|
## is not in the BNF.
|
||||||
Atomic = Or([ TypeInfo + lbr + Const + rbr, Variable]) + optprime
|
TypedConstant = TypeInfo + lbr + Const + rbr + optprime
|
||||||
Atomic.setParseAction(lambda s,l,t: [ If.Atomic(t) ])
|
TypedConstant.setParseAction(lambda s,l,t: [
|
||||||
|
If.TypedConstant(t[0],t[1],t[2]) ])
|
||||||
|
Atomic = Or(TypedConstant, Variable)
|
||||||
|
|
||||||
### TEST
|
### TEST
|
||||||
#print Const.parseString("Cas'")
|
print Atomic.parseString("mr(Cas)'")
|
||||||
#print Atomic.parseString("mr(Cas)'")
|
print Atomic.parseString("nonce(Koen)")
|
||||||
#print Atomic.parseString("nonce(Koen)")
|
|
||||||
|
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
# Messages
|
# Messages
|
||||||
@ -86,7 +98,9 @@ def ruleParser ():
|
|||||||
|
|
||||||
|
|
||||||
# Agents etc
|
# Agents etc
|
||||||
Agent = Or ([Literal("mr") + lbr + Const + rbr, Variable])
|
AgentMr = Literal("mr") + lbr + Const + rbr
|
||||||
|
AgentMr.setParseAction(lambda s,l,t: [ If.TypedConstant("mr",t[1]) ])
|
||||||
|
Agent = Or ([AgentMr, Variable])
|
||||||
KeyTable = Or ([Literal("table") + lbr + Const + rbr, Variable])
|
KeyTable = Or ([Literal("table") + lbr + Const + rbr, Variable])
|
||||||
KeyTableApp = Literal("tb") + lbr + KeyTable + comma + Agent + rbr + optprime
|
KeyTableApp = Literal("tb") + lbr + KeyTable + comma + Agent + rbr + optprime
|
||||||
|
|
||||||
@ -101,7 +115,7 @@ def ruleParser ():
|
|||||||
Function = Literal("funct") + lbr + futerm + comma + Message + rbr
|
Function = Literal("funct") + lbr + futerm + comma + Message + rbr
|
||||||
|
|
||||||
# Message composition
|
# Message composition
|
||||||
Concatenation = Literal("c") + lbr + Message + comma + Message + rbr
|
Concatenation = Literal("c").suppress() + lbr + Message + comma + Message + rbr
|
||||||
Composed = Or([ Concatenation, SymmetricCypher, XOR,
|
Composed = Or([ Concatenation, SymmetricCypher, XOR,
|
||||||
PublicCypher, Function, KeyTable, KeyTableApp ])
|
PublicCypher, Function, KeyTable, KeyTableApp ])
|
||||||
Message << Or ([Composed, Atomic])
|
Message << Or ([Composed, Atomic])
|
||||||
@ -120,7 +134,7 @@ def ruleParser ():
|
|||||||
MsgEtc = Literal("etc")
|
MsgEtc = Literal("etc")
|
||||||
MsgEtc.setParseAction(lambda s,l,t: [ If.Message([ If.Special("etc") ]) ])
|
MsgEtc.setParseAction(lambda s,l,t: [ If.Message([ If.Special("etc") ]) ])
|
||||||
MsgVariable = Group(Variable)
|
MsgVariable = Group(Variable)
|
||||||
MsgVariable.setParseAction(lambda s,l,t: [ If.Message([ If.Atomic([ t[0][0] ]) ]) ])
|
MsgVariable.setParseAction(lambda s,l,t: [ If.Message(t[0]) ])
|
||||||
|
|
||||||
MsgList = Forward()
|
MsgList = Forward()
|
||||||
MsgComp = Literal("c") + lbr + Message + comma + MsgList + rbr
|
MsgComp = Literal("c") + lbr + Message + comma + MsgList + rbr
|
||||||
@ -132,6 +146,7 @@ def ruleParser ():
|
|||||||
|
|
||||||
### TEST
|
### TEST
|
||||||
#print Message.parseString("xKb")
|
#print Message.parseString("xKb")
|
||||||
|
#print Message.parseString("mr(Cas)")
|
||||||
#print MsgList.parseString("etc")
|
#print MsgList.parseString("etc")
|
||||||
#print MsgList.parseString("c(xKb,etc)")
|
#print MsgList.parseString("c(xKb,etc)")
|
||||||
#print MsgList.parseString("c(xA,c(xB,c(xKa,c(xKa',c(xKb,etc)))))")
|
#print MsgList.parseString("c(xA,c(xB,c(xKa,c(xKa',c(xKb,etc)))))")
|
||||||
|
Loading…
Reference in New Issue
Block a user