forked from AnB2Murphi/Strand_Space2Murphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocols.ml
3799 lines (3713 loc) · 214 KB
/
protocols.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
open Core
open Proctype
open Func
(*-----------------------------------transition part-------------------------------------------------*)
let printMurphiConsTypeVars ag k env=
let msgs = getMsgOfRoles k in
let nlist = getNonces msgs in
let rlist = getRolesFromKnws k [] in
let clist = del_duplicate (getConsts msgs) in
let rolesOfEnv = getRolesFromEnv env [] in
let nonceOfEnv = getNonceFromEnv env [] in
let allNonce = del_duplicate (nlist @ nonceOfEnv) in
let constOfEnv = getConstFromEnv env [] in
let allConst = del_duplicate (clist @ constOfEnv) in
let roleOfAgent = getAgentRole ag in (* Get all roles *)
let actOfAgent = List.map ~f:(fun r->getActsList ag r) roleOfAgent in (*get role's action*)
let lensOfactStr = List.map ~f: List.length actOfAgent in(*length of actor*)
let allOfAct = (getAllActsList ag) in
let seqlist = List.sort ~cmp:(fun x y -> x-y) (del_duplicate (List.concat (List.map ~f:getSeqByActions (allOfAct)))) in
let patlist = List.concat (List.map ~f:getPatList (allOfAct)) in (*get all patterns from actions*)
let patlist1 = patlist @ [`Sk "A"] in
let non_dup1 = del_duplicate patlist1 in (* delete duplicate *)
let pats = getEqvlMsgPattern non_dup1 in
let() = print_endline (sprintf "%s" (String.concat ~sep:"\n" (List.mapi ~f:(fun i x -> sprintf "%d:%s" (i+1) (print_message x)) pats))) in
let tlist = getTmp non_dup1 in
let concatParts = ref "\n concatPart: Array[msgLen] of indexType;" in
sprintf "const\n" ^
String.concat ~sep:"\n" (List.map ~f:(fun r -> sprintf " role%sNum:1;" r) rlist) ^
"
totalFact:100;
msgLength:10;
chanNum:18;
invokeNum:10;\n" ^
(* print type*)
sprintf "type
indexType:0..totalFact;\n"^
String.concat ~sep:"\n" (List.map ~f:(fun r -> sprintf " role%sNums:1..role%sNum;" r r) rlist) ^
"
msgLen:0..msgLength;
chanNums:0..chanNum;
invokeNums:0..invokeNum;\n"^
sprintf "
AgentType : enum{anyAgent,%s}; ---Intruder
NonceType : enum{anyNonce%s};
ConstType : enum{anyNumber%s};
MsgType : enum {null,agent,nonce,key,aenc,senc,sign,concat,hash,tmp,mod,e,number};
" (agents2Str rolesOfEnv) (if List.length allNonce = 0 then "" else ", "^nonce2Str allNonce) (if List.length allConst = 0 then "" else ", "^const2Str allConst )
^
sprintf "
EncryptType : enum{PK,SK,Symk,MsgK};
KeyType: record
encType: EncryptType;
ag: AgentType;
ag1:AgentType;
ag2:AgentType;
m:indexType;
end;\n\n %s;\n" (agentSStatus rlist lensOfactStr) (*
AStatus : enum {A1,A2,A3}; ---the roles status should be derived from actions and the principals
BStatus : enum {B1,B2,B3};*)
^"
Message: record
msgType : MsgType;
ag : AgentType;
noncePart : NonceType;
constPart : ConstType;
tmpPart : indexType;
k : KeyType;
modMsg1 : indexType;
modMsg2 : indexType;
hashMsg : indexType;
expMsg1 : indexType;
expMsg2 : indexType;
signMsg : indexType;
signKey : indexType;
aencMsg : indexType;
aencKey : indexType;
sencMsg : indexType;
sencKey : indexType;"^ !concatParts ^ "--- concatParts could be written in arrays: concatPart: Array[msgLen] of indexType" ^"
length : indexType;
end;
Channel: record
msg : Message;
sender : AgentType;
receiver : AgentType;
empty : boolean;
end;
" ^ printMurphiRecords k allNonce rlist tlist allConst^ (* print records of principals *)
(* ---RoleIntruder: record
--- B : AgentType;
---send; *)
"
msgSet: record
content : Array[indexType] of indexType;
length : indexType;
end;
var
ch : Array[chanNums] of Channel;\n"^
sprintf " %s;\n" (rlistToVars rlist )^
"
---intruder : RoleIntruder;
msgs : Array[indexType] of Message;
msg_end: indexType;\n"^
sprintf "%s\n" (printPatSetVars pats) ^
sprintf " %s\n Spy_known: Array[indexType] of boolean;\n %s
---systemEvent : array[eventNums] of Event;
---eve_end : eventNums;
emit: Array[indexType] of boolean;
gnum : indexType;\n\n" (rlistToKnows rlist ) (intruderEmitIntoCh seqlist)(* global num*)
(*--------------------------------------------------------print precedure -----------------------------------------------------------*)
(*synthesis of a messages of pati.*)
let atoms2Parms atoms =
let paraList = ref [] in
for i = 0 to List.length atoms -1 do
match List.nth atoms i with
|Some(`Var n) ->let n1 = n ^ ":NonceType" in
if listwithout !paraList n1 then paraList := !paraList@[n1]
|Some(`Str r) ->let r1 = r ^ ":AgentType" in
if listwithout !paraList r1 then paraList := !paraList@[r1]
|Some(`Pk role) ->let r = role^"Pk:AgentType" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`Sk role )->let r = role^"Sk:AgentType" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`Tmp mn) -> let r = mn ^":Message" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`K(r1,r2)) -> let symk1 = r1^"symk1:AgentType" in
let symk2 = r2^"symk2:AgentType" in
if listwithout !paraList symk1 then paraList := !paraList@[symk1];
if listwithout !paraList symk2 then paraList := !paraList@[symk2]
|Some(`Const n) -> let n1 = n^":ConstType" in
if listwithout !paraList n1 then
paraList := !paraList@[n1]
|_ -> ()
done;
String.concat ~sep:"; " !paraList
let atoms2Parms1 atoms =
let paraList = ref [] in
for i = 0 to List.length atoms -1 do
match List.nth atoms i with
|Some(`Var n) ->let n1 = "Var "^ n^ ":NonceType" in
if listwithout !paraList n1 then paraList := !paraList@[n1]
|Some(`Const n) ->let n1 = "Var "^ n^ ":ConstType" in
if listwithout !paraList n1 then paraList := !paraList@[n1]
|Some(`Str r) ->let r1 ="Var "^ r ^ ":AgentType" in
if listwithout !paraList r1 then paraList := !paraList@[r1]
|Some(`Tmp m) ->let m1 ="Var "^ m ^ ":Message" in
if listwithout !paraList m1 then paraList := !paraList@[m1]
|Some(`Pk role) ->let r ="Var "^ role^"Pk:AgentType" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`Sk role )->let r ="Var "^ role^"Sk:AgentType" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`K(r1,r2)) -> let symk1 ="Var "^ r1^"symk1:AgentType" in
let symk2 ="Var "^ r2^"symk2:AgentType" in
if listwithout !paraList symk1 then paraList := !paraList@[symk1];
if listwithout !paraList symk2 then paraList := !paraList@[symk2]
|_ -> ()
done;
String.concat ~sep:"; " !paraList
let atoms2Dest1 atoms =
let paraList = ref [] in
for i = 0 to List.length atoms -1 do
match List.nth atoms i with
|Some(`Var n) ->let n1 = n in
if listwithout !paraList n1 then paraList := !paraList@[n1]
|Some(`Const n) ->let n1 = n in
if listwithout !paraList n1 then paraList := !paraList@[n1]
|Some(`Str r) ->let r1 =r in
if listwithout !paraList r1 then paraList := !paraList@[r1]
|Some(`Tmp m) ->let m1 = m in
if listwithout !paraList m1 then paraList := !paraList@[m1]
|Some(`Pk role) ->let r = role^"Pk" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`Sk role )->let r = role^"Sk" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`K(r1,r2)) -> let symk1 = r1^"symk1" in
let symk2 = r2^"symk2" in
if listwithout !paraList symk1 then paraList := !paraList@[symk1];
if listwithout !paraList symk2 then paraList := !paraList@[symk2]
|_ -> ()
done;
String.concat ~sep:";\n clear " !paraList
let genGet_msgNoCode () =
sprintf "
procedure get_msgNo(msg:Message; Var num:indexType);
var index:indexType;
j:indexType;
flag:boolean;
begin
index:=0;
for i: indexType do
if (msgs[i].msgType = msg.msgType) then
if ( (msg.msgType=agent & msgs[i].ag=msg.ag)
| (msg.msgType=nonce & msgs[i].noncePart=msg.noncePart)
| (msg.msgType=tmp & msgs[i].tmpPart=msg.tmpPart)
| (msg.msgType=mod & msgs[i].modMsg1=msg.modMsg1 & msgs[i].modMsg2=msg.modMsg2)
| (msg.msgType=e & msgs[i].expMsg1=msg.expMsg1 & msgs[i].expMsg2=msg.expMsg2)
| (msg.msgType=number & msgs[i].constPart=msg.constPart)
| (msg.msgType=key & (msgs[i].k.encType=msg.k.encType & msg.k.encType != Symk & msgs[i].k.ag=msg.k.ag))
| (msg.msgType=key & (msgs[i].k.encType=msg.k.encType & msg.k.encType = Symk & msgs[i].k.ag1=msg.k.ag1 & msgs[i].k.ag2=msg.k.ag2))
| (msg.msgType=aenc & (msgs[i].aencMsg=msg.aencMsg & msgs[i].aencKey=msg.aencKey))
| (msg.msgType=senc & (msgs[i].sencMsg=msg.sencMsg & msgs[i].sencKey=msg.sencKey))
| (msg.msgType=sign & (msgs[i].signMsg=msg.signMsg & msgs[i].signKey=msg.signKey))
| (msg.msgType=hash & (msgs[i].hashMsg=msg.hashMsg))
) then
index:=i;
elsif (msg.msgType=concat & msg.length = msgs[i].length) then
j := msg.length;
flag := true;
while j > 0 do
if (msg.concatPart[j] != msgs[i].concatPart[j]) then
flag := false;
endif;
j := j - 1;
end;
if (flag) then
index := i;
endif;
endif;
endif;
endfor;
num := index;
end;\n"
let genPrintMsgCode () =
sprintf "
procedure printMsg(msg:Message);
var i:indexType;
begin
if msg.msgType=null then
put \"null\\n\";
elsif msg.msgType=agent then
put msg.ag;
elsif msg.msgType=nonce then
put msg.noncePart;
elsif msg.msgType=key then
if msg.k.encType=PK then
put \"PK(\";
put msg.k.ag;
put \")\";
elsif msg.k.encType=SK then
put \"SK(\";
put msg.k.ag;
put \")\";
elsif msg.k.encType=Symk then
put \"SymK(\";
put msg.k.ag1;
put \",\";
put msg.k.ag2;
put \")\";
endif;
elsif msg.msgType=aenc then
put \"aenc{\";
printMsg(msgs[msg.aencMsg]);
put \"}\";
printMsg(msgs[msg.aencKey]);
elsif msg.msgType=senc then
put \"senc{\";
printMsg(msgs[msg.sencMsg]);
put \"}\";
printMsg(msgs[msg.sencKey]);
elsif msg.msgType = sign then
put \"sign{\";
printMsg(msgs[msg.signMsg]);
put \"}\";
printMsg(msgs[msg.signKey]);
elsif msg.msgType = hash then
put \"hash(\";
printMsg(msgs[msg.hashMsg]);
put \");\"
elsif msg.msgType=mod then
put \"mod{\";
printMsg(msgs[msg.modMsg1]);
put \",\";
printMsg(msgs[msg.modMsg2]);
put \"}\";
elsif msg.msgType= e then
put \"exp{\";
printMsg(msgs[msg.expMsg1]);
put \",\";
printMsg(msgs[msg.expMsg2]);
put \"}\";
elsif msg.msgType = number then
put msg.constPart;
elsif msg.msgType = tmp then
put \"tmp{\";
printMsg(msgs[msg.tmpPart]);
put \"}\";
elsif msg.msgType=concat then
put \"concat(\";
i := 1;
while i < msg.length do
printMsg(msgs[msg.concatPart[i]]);
put \",\";
i := i+1;
end;
printMsg(msgs[msg.concatPart[i]]);
put\")\";
endif;
end;\n"
;;
let genInverseKeyCode ()=
sprintf "function inverseKey(msgK:Message):Message;
var key_inv:Message;
begin
key_inv.msgType := null;
if (msgK.msgType=key) then
key_inv.msgType := msgK.msgType;
if (msgK.k.encType = PK) then
key_inv.k.encType := SK;
key_inv.k.ag := msgK.k.ag;
elsif (msgK.k.encType = SK) then
key_inv.k.encType := PK;
key_inv.k.ag := msgK.k.ag;
elsif (msgK.k.encType = Symk) then
key_inv.k.encType := Symk;
key_inv.k.ag1 := msgK.k.ag1;
key_inv.k.ag2 := msgK.k.ag2;
endif;
elsif (msgK.msgType != key) then
if (msgK.k.encType = MsgK) then
key_inv.msgType := msgK.msgType;
---key_inv.k.m := msgK.k.m;
if (msgK.msgType = mod) then
---key_inv.modMsg1 := msgK.modMsg1;
---key_inv.modMsg2 := msgK.modMsg2;
---elsif (msgK.msgType = e) then
---key_inv.expMsg1 := msgK.expMsg1;
---key_inv.expMsg2 := msgK.expMsg2;
key_inv := msgs[msgs[msgK.modMsg1].expMsg1];
key_inv.k.encType := MsgK;
elsif (msgK.msgType = hash) then
key_inv := msgs[msgK.hashMsg];
key_inv.k.encType := MsgK;
endif;
endif;
endif;
return key_inv;
end;\n"
let genInverseKeyIndexCode ()=
sprintf "function inverseKeyIndex(msgK:Message):indexType;
var key_inv:Message;
index : indexType;
begin
key_inv := inverseKey(msgK);
get_msgNo(key_inv,index);
return index;
end;\n"
let genJudgeCode () =
sprintf "function judge(msg:Message;ag:AgentType;msg1:Message) :boolean;
begin
if msg.msgType = aenc & msg1.msgType != tmp then
return msgs[msg.aencKey].k.ag = ag;
elsif msg.msgType = aenc & msg1.msgType = tmp then
return true;
elsif msg.msgType = senc then
---if msgs[msg.sencKey].k.m =0 then
return (msgs[msg.sencKey].k.ag1 = ag |msgs[msg.sencKey].k.ag2 = ag)
---endif;
endif;
return true;
end;\n\n"
let genLookUpCode () =
sprintf "function lookUp(msg: Message): indexType; --- not used.
var index : indexType;
begin
index:=0;
for i: indexType do
if(msgs[i].msgType=msg.msgType) then
if(msgs[i].msgType=agent & msgs[i].ag=msg.ag) then
index := i;
elsif(msgs[i].msgType=nonce & msgs[i].noncePart=msg.noncePart) then
index := i;
elsif(msgs[i].msgType=key & (msgs[i].k.encType=msg.k.encType & msgs[i].k.ag=msg.k.ag)) then
index := i;
elsif(msgs[i].msgType = aenc & (msgs[i].aencKey=msg.aencKey & msgs[i].aencMsg=msg.aencMsg)) then
index := i;
elsif(msgs[i].msgType = senc & (msgs[i].sencKey=msg.sencKey & msgs[i].sencMsg=msg.sencMsg)) then
index := i;
elsif(msgs[i].msgType = concat & (msgs[i].concatPart[1]=msg.concatPart[1] & msgs[i].concatPart[2]=msg.concatPart[2])) then
index := i;
endif;
endif;
endfor;
return index;
end;\n";
;;
(* generate m by its submsgs*)
let consMsgBySubs m patList =
let i = getPatNum m patList in
match m with
|`Aenc(m1,k1) -> (* submessage are m1 and k1*)
let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numK1 = getPatNum k1 patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = aenc) then\n"^
sprintf " if (msgs[i].aencMsg = msgNo%d1 & msgs[i].aencKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := aenc;\n" ^
sprintf " msg.aencMsg := msgNo%d1;\n" numM1 ^
sprintf " msg.aencKey := msgNo%d2;\n" numK1 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = aenc) then\n"^
sprintf " if (msgs[i].aencMsg = msgNo%d1 & msgs[i].aencKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index := msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n\n"
|`Sign(m1,k1) -> (* submessage are m1 and k1*)
let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numK1 = getPatNum k1 patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = sign) then\n"^
sprintf " if (msgs[i].signMsg = msgNo%d1 & msgs[i].signKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := sign;\n" ^
sprintf " msg.signMsg := msgNo%d1;\n" numM1 ^
sprintf " msg.signKey := msgNo%d2;\n" numK1 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = sign) then\n"^
sprintf " if (msgs[i].signMsg = msgNo%d1 & msgs[i].signKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index := msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n\n"
|`Hash(m1) -> (* submessage are m1 *)
let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
sprintf "function construct%dBy%d(msgNo%d1:indexType):Message;\n" i numM1 numM1 ^
sprintf " var index: indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = hash) then\n"^
sprintf " if (msgs[i].hashMsg = msgNo%d1) then\n" numM1 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := hash;\n" ^
sprintf " msg.hashMsg := msgNo%d1;\n" numM1 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n\n" ^
sprintf "function constructIndex%dBy%d(msgNo%d1:indexType):indexType;\n" i numM1 numM1 ^
sprintf " var index: indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = hash) then\n"^
sprintf " if (msgs[i].hashMsg = msgNo%d1) then\n" numM1 ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index := msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n\n"
|`Senc(m1,symK) -> (* submessage are m1 and symK *)
let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numK = getPatNum symK patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numK numM1 numK^
sprintf " var index: indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = senc) then\n"^
sprintf " if (msgs[i].sencMsg = msgNo%d1 & msgs[i].sencKey = msgNo%d2) then\n" numM1 numK ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := senc;\n" ^
sprintf " msg.sencMsg := msgNo%d1;\n" numM1 ^
sprintf " msg.sencKey := msgNo%d2;\n" numK ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numK numM1 numK^
sprintf " var index: indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = senc) then\n"^
sprintf " if (msgs[i].sencMsg = msgNo%d1 & msgs[i].sencKey = msgNo%d2) then\n" numM1 numK ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index:= msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n"
|`Sign(m1,k1) -> (* submessage are m1 and k1*)
let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numK1 = getPatNum k1 patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = sign) then\n"^
sprintf " if (msgs[i].signMsg = msgNo%d1 & msgs[i].signKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := sign;\n" ^
sprintf " msg.signMsg := msgNo%d1;\n" numM1 ^
sprintf " msg.signKey := msgNo%d2;\n" numK1 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numK1 numM1 numK1^
sprintf " var index: indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = sign) then\n"^
sprintf " if (msgs[i].signMsg = msgNo%d1 & msgs[i].signKey = msgNo%d2) then\n" numM1 numK1 ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index := msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n\n"
|`Concat msgs -> (* submessage are elements in msgs*)
let subMsgNo = String.concat (List.map ~f:(fun m -> sprintf "%d" (getPatNum m patList)) msgs) in
let msgNoStr = String.concat ~sep:"," (List.mapi ~f:(fun j m -> sprintf "msgNo%d" (j+1)) msgs) in
let ifStr = String.concat ~sep:" & " (List.mapi ~f:(fun j m -> sprintf "msgs[i].concatPart[%d] = msgNo%d" (j+1) (j+1) )msgs)
in
let assignStr = String.concat (List.mapi ~f:(fun j m -> sprintf " msg.concatPart[%d] := msgNo%d;\n" (j+1) (j+1)) msgs)
in
sprintf "function construct%dBy%s(%s:indexType):Message;\n" i subMsgNo msgNoStr ^
sprintf " var index : indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = concat & msgs[i].length = %d) then\n" (List.length msgs) ^
sprintf " if (%s) then\n" ifStr ^
sprintf " index := i;\n"^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n"^
sprintf " endif;\n" ^
sprintf " endfor;\n"^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := concat;\n" ^
sprintf "%s" assignStr ^
sprintf " msg.length := %d;\n" (List.length msgs)^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n\n" ^
sprintf "function constructIndex%dBy%s(%s:indexType):indexType;\n" i subMsgNo msgNoStr ^
sprintf " var index : indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = concat & msgs[i].length = %d) then\n" (List.length msgs) ^
sprintf " if (%s) then\n" ifStr ^
sprintf " index := i;\n"^
sprintf " endif;\n"^
sprintf " endif;\n" ^
sprintf " endfor;\n"^
sprintf " if (index = 0) then \n"^
sprintf " index:=msg_end+1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n\n"
|`Exp(m1,m2) -> let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numM2 = getPatNum m2 patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numM2 numM1 numM2 ^
sprintf " var index : indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = e) then\n"^
sprintf " if (msgs[i].expMsg1 = msgNo%d1 & msgs[i].expMsg2 = msgNo%d2) then\n" numM1 numM2 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := e;\n" ^
sprintf " msg.expMsg1 := msgNo%d1;\n" numM1 ^
sprintf " msg.expMsg2 := msgNo%d2;\n" numM2 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numM2 numM1 numM2 ^
sprintf " var index : indexType;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = e) then\n"^
sprintf " if (msgs[i].expMsg1 = msgNo%d1 & msgs[i].expMsg2 = msgNo%d2) then\n" numM1 numM2 ^
sprintf " index := i;\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index := msg_end+1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n"
|`Mod(m1,m2) -> let numM1 = getPatNum m1 patList in (* construct_i_by_numM1_numK1 *)
let numM2 = getPatNum m2 patList in
sprintf "function construct%dBy%d%d(msgNo%d1, msgNo%d2:indexType):Message;\n" i numM1 numM2 numM1 numM2 ^
sprintf " var index : indexType;\n"^
sprintf " msg : Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = mod) then\n"^
sprintf " if (msgs[i].modMsg1 = msgNo%d1 & msgs[i].modMsg2 = msgNo%d2) then\n" numM1 numM2 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " msg.msgType := mod;\n" ^
sprintf " msg.modMsg1 := msgNo%d1;\n" numM1 ^
sprintf " msg.modMsg2 := msgNo%d2;\n" numM2 ^
sprintf " msg.length := 1;\n"^
sprintf " endif;\n"^
sprintf " return msg;\n" ^
sprintf " end;\n" ^
sprintf "function constructIndex%dBy%d%d(msgNo%d1, msgNo%d2:indexType):indexType;\n" i numM1 numM2 numM1 numM2 ^
sprintf " var index : indexType;\n msg:Message;\n begin\n"^
sprintf " index := 0;\n"^
sprintf " for i :indexType do\n"^
sprintf " if (msgs[i].msgType = mod) then\n"^
sprintf " if (msgs[i].modMsg1 = msgNo%d1 & msgs[i].modMsg2 = msgNo%d2) then\n" numM1 numM2 ^
sprintf " index := i;\n" ^
sprintf " msg := msgs[index];\n" ^
sprintf " endif;\n" ^
sprintf " endif;\n" ^
sprintf " endfor;\n" ^
sprintf " if (index = 0) then \n"^
sprintf " index:=msg_end + 1;\n" ^
sprintf " endif;\n"^
sprintf " return index;\n" ^
sprintf " end;\n"
| _ -> sprintf "--- Sorry, construct_function of this pattern has not been written!\n\n"
;;
let genExistCode () =
sprintf "function exist(PatnSet:msgSet; msgNo:indexType):boolean;
var flag:boolean;
begin
flag := false;
for i:msgLen do
if (msgNo != 0 & PatnSet.content[i] = msgNo) then
flag := true;
endif;
endfor;
return flag;
end;\n";
;;
(* Generating function matchAgent() code *)
let genMatchAgent () =
sprintf "function matchAgent(locAg: AgentType; Var Ag: AgentType):boolean; ---if ag equals to locAg which was derived from recieving msg, or anyAgent, then true
var flag : boolean;
begin
flag := false;
if (Ag = anyAgent) then
flag := true;
Ag := locAg;
elsif (locAg = Ag) then
flag := true;
else
flag := false;
endif;
return flag;
end;\n\n"
;;
let genMatchTmp () =
sprintf "function matchTmp(locm:Message;Var m:Message):boolean; ---if m equals to locm which was derived from recieving msg, or tmp, then true
var flag : boolean;
var index1,index2 :indexType;
begin
flag := false;
get_msgNo(m,index2);
get_msgNo(locm,index1);
if (m.msgType = tmp) then
if (m.tmpPart =0) then
flag := true;
m:=locm;
elsif ( index1 = index2) then
flag := true;
endif;
else
flag := false;
endif;
return flag;
end;\n\n"
(* Generating function matchNonce() code *)
let genMatchNonce () =
sprintf "function matchNonce(locNa: NonceType; Var Na: NonceType):boolean; ---if Na equals to locNa which was derived from recieving msg, or anyNonce, then true
var flag : boolean;
begin
flag := false;
if (Na = anyNonce) then
flag := true;
Na := locNa;
elsif (locNa = Na) then
flag:=true;
else
flag := false;
endif;
return flag;
end;\n\n"
;;
let genMatchNumber () =
sprintf "function matchNumber(locNm: ConstType; Var Nm: ConstType):boolean; ---if Nm equals to locNm which was derived from recieving msg, or anyNumber, then true
var flag : boolean;
begin
flag := false;
if (Nm = anyNumber) then
flag := true;
Nm := locNm;
elsif locNm = Nm then
flag := true;
else
flag := false;
endif;
return flag;
end;\n\n"
(* Generating function match(msg1,msg2) code *)
let rec genMatchMsg ()=
genMatch() ^ genMatchPat()
and genMatch () =
sprintf "function match(m1:Message; var m2:Message):boolean;
var concatFlag: boolean;
i,msgNo: indexType;
begin
if m1.msgType = tmp then
return true;
elsif m1.msgType = agent & m2.msgType = agent then
return matchAgent(m1.ag,m2.ag); ---ag and noncePart should be initiallized as anyAgent or anyNonce (m1.ag != anyAgent & m2.ag != anyAgent &)
elsif m1.msgType = nonce & m2.msgType = nonce then
return matchNonce(m1.noncePart,m2.noncePart); --- m1.noncePart != anyNonce & m2.noncePart != anyNonce &
elsif m1.msgType = number & m2.msgType = number then
return matchNumber(m1.constPart,m2.constPart);
elsif m1.msgType = key & m2.msgType = key then
if m1.k.encType = PK then
return (m1.k.encType = m2.k.encType) & (matchAgent(m1.k.ag, m2.k.ag));
elsif m1.k.encType = SK then
return (m1.k.encType = m2.k.encType) & (matchAgent(m1.k.ag, m2.k.ag));
elsif m1.k.encType = Symk then
return (m1.k.encType = m2.k.encType) & (matchAgent(m1.k.ag1, m2.k.ag1)) & (matchAgent(m1.k.ag2, m2.k.ag2));
endif;
elsif m1.msgType = aenc & m2.msgType = aenc then
return match(msgs[m1.aencMsg], msgs[m2.aencMsg]) & match(msgs[m1.aencKey], msgs[m2.aencKey]);
elsif m1.msgType = senc & m2.msgType = senc then
return true;
--match(msgs[m1.sencMsg], msgs[m2.sencMsg]) & match(msgs[m1.sencKey], msgs[m2.sencKey]);
elsif (m1.msgType = mod & m2.msgType = mod) then
return match(msgs[m1.modMsg1],msgs[m2.modMsg1]) & match(msgs[m1.modMsg2],msgs[m2.modMsg2]);
elsif (m1.msgType = e & m2.msgType = e) then
return match(msgs[m1.expMsg1],msgs[m2.expMsg1]) & match(msgs[m1.expMsg2],msgs[m2.expMsg2]);
elsif (m1.msgType = concat & m2.msgType = concat) & (m1.length = m2.length) then
concatFlag := true;
i := m1.length;
while (i > 0 & concatFlag)do
concatFlag := concatFlag & match(msgs[m1.concatPart[i]], msgs[m2.concatPart[i]]);
i := i-1;
end;
return concatFlag;
else
return false;
endif;
end;\n\n"
and genMatchPat () =
sprintf "function matchPat(m1:Message; sPatnSet: msgSet):boolean;
var flag:boolean;
i : indexType;
begin
flag := false;
i := 1;
while (i<sPatnSet.length+1) do
if(match(m1,msgs[sPatnSet.content[i]])) then
flag := true;
endif;
i := i+1;
end;
return flag;
end;\n\n"
;;
let atom2Str atoms =
let paraList = ref [] in
for i = 0 to List.length atoms -1 do
match List.nth atoms i with
|Some(`Tmp mn) ->if listwithout !paraList mn then paraList := !paraList@[mn]
|Some(`Var n) -> if listwithout !paraList n then paraList := !paraList@[n]
|Some(`Str r) -> if listwithout !paraList r then paraList := !paraList@[r]
|Some(`Const r) -> if listwithout !paraList r then paraList := !paraList@[r]
|Some(`Pk role) ->let r = role^"Pk" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`Sk role )->let r = role^"Sk" in
if listwithout !paraList r then
paraList := !paraList@[r]
|Some(`K(r1,r2)) -> let symk1 = r1^"symk1" in
let symk2 = r2^"symk2" in
if listwithout !paraList symk1 then paraList := !paraList@[symk1];
if listwithout !paraList symk2 then paraList := !paraList@[symk2]
|_ -> ()
done;
String.concat ~sep:", " !paraList
let genSynthCode m i patList =
let atoms = getAtoms m in
let atoms = del_duplicate atoms in
let str1 = sprintf "---pat%d: %s \nprocedure lookAddPat%d" i (print_message m) i ^
sprintf "(%s; Var msg:Message; Var num : indexType);\n" (atoms2Parms atoms)
in
match m with
|`Aenc(m1,k1) -> begin
let i1= getPatNum m1 patList in
let i2= getPatNum k1 patList in
let keyAg=match k1 with
|`Pk role -> role^"Pk"
|`Sk role -> role^"Sk"
|_->"null"
in
let m1Atoms = getAtoms m1 in
let k1Atoms = getAtoms k1 in
str1 ^
sprintf " Var msg1, msg2: Message;\n index,i1,i2:indexType;\n begin\n"^
sprintf " index:=0;\n"^
sprintf " lookAddPat%d(%s,msg1,i1);\n" i1 (atom2Str m1Atoms)^
sprintf " lookAddPat%d(%s,msg2,i2);\n" i2 (if keyAg = "null" then (atom2Str k1Atoms) else keyAg)^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = aenc) then\n"^
sprintf " if (msgs[i].aencMsg = i1 & msgs[i].aencKey = i2) then\n"^
sprintf " index:=i;\n"^
sprintf " endif;\n"^
sprintf " endif;\n"^
sprintf " endfor;\n"^
sprintf " if(index=0) then\n"^
sprintf " msg_end := msg_end + 1 ;\n index := msg_end;\n msgs[index].msgType := aenc;\n msgs[index].aencMsg := i1; \n msgs[index].aencKey := i2; \n %smsgs[index].length := 1;\n" (if keyAg = "null" then (sprintf "msgs[i2].k.encType := MsgK;\n msgs[i2].k.m := i2;\n") else "")^
sprintf " endif;\n"^
sprintf " num:=index;\n msg:=msgs[index];\n end;\n\n";
end;
|`Sign(m1,k1) -> begin
let i1= getPatNum m1 patList in
let i2= getPatNum k1 patList in
let keyAg=match k1 with
|`Pk role -> role^"Pk"
|`Sk role -> role^"Sk"
|_->"null"
in
let m1Atoms = getAtoms m1 in
let k1Atoms = getAtoms k1 in
str1 ^
sprintf " Var msg1, msg2: Message;\n index,i1,i2:indexType;\n begin\n"^
sprintf " index:=0;\n"^
sprintf " lookAddPat%d(%s,msg1,i1);\n" i1 (atom2Str m1Atoms)^
sprintf " lookAddPat%d(%s,msg2,i2);\n" i2 (if keyAg = "null" then (atom2Str k1Atoms) else keyAg)^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = sign) then\n"^
sprintf " if (msgs[i].signMsg = i1 & msgs[i].signKey = i2) then\n"^
sprintf " index:=i;\n"^
sprintf " endif;\n"^
sprintf " endif;\n"^
sprintf " endfor;\n"^
sprintf " if(index=0) then\n"^
sprintf " msg_end := msg_end + 1 ;\n index := msg_end;\n msgs[index].msgType := sign;\n msgs[index].signMsg := i1; \n msgs[index].signKey := i2; \n %s msgs[index].length := 1;\n" (if keyAg = "null" then (sprintf "msgs[i2].k.encType := MsgK;\n msgs[i2].k.m := i2;\n") else "")^
sprintf " endif;\n"^
sprintf " num:=index;\n msg:=msgs[index];\n end;\n\n";
end;
|`Exp(m1,m2) -> begin
let i1= getPatNum m1 patList in
let i2= getPatNum m2 patList in
let m1Atoms = getAtoms m1 in
let m2Atoms = getAtoms m2 in
str1 ^
sprintf " Var msg1, msg2: Message;\n index,i1,i2:indexType;\n begin\n"^
sprintf " index:=0;\n"^
sprintf " lookAddPat%d(%s,msg1,i1);\n" i1 (atom2Str m1Atoms)^
sprintf " lookAddPat%d(%s,msg2,i2);\n" i2 (atom2Str m2Atoms)^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = e) then\n"^
sprintf " if (msgs[i].expMsg1 = i1 & msgs[i].expMsg2 = i2) then\n"^
sprintf " index:=i;\n"^
sprintf " endif;\n"^
sprintf " endif;\n"^
sprintf " endfor;\n"^
sprintf " if(index=0) then\n"^
sprintf " msg_end := msg_end + 1 ;\n index := msg_end;\n msgs[index].msgType := e;\n msgs[index].expMsg1 := i1; \n msgs[index].expMsg2 := i2; \n msgs[index].length := 1;\n"^
sprintf " endif;\n"^
sprintf " num:=index;\n msg:=msgs[index];\n end;\n\n";
end;
|`Mod(m1,m2) -> begin
let i1= getPatNum m1 patList in
let i2= getPatNum m2 patList in
let m1Atoms = getAtoms m1 in
let m2Atoms = getAtoms m2 in
str1 ^
sprintf " Var msg1, msg2: Message;\n index,i1,i2:indexType;\n begin\n"^
sprintf " index:=0;\n"^
sprintf " lookAddPat%d(%s,msg1,i1);\n" i1 (atom2Str m1Atoms)^
sprintf " lookAddPat%d(%s,msg2,i2);\n" i2 (atom2Str m2Atoms)^
sprintf " for i : indexType do\n"^
sprintf " if (msgs[i].msgType = mod) then\n"^
sprintf " if (msgs[i].modMsg1 = i1 & msgs[i].modMsg2 = i2) then\n"^
sprintf " index:=i;\n"^
sprintf " endif;\n"^
sprintf " endif;\n"^
sprintf " endfor;\n"^
sprintf " if(index=0) then\n"^
sprintf " msg_end := msg_end + 1 ;\n index := msg_end;\n msgs[index].msgType := mod;\n msgs[index].modMsg1 := i1; \n msgs[index].modMsg2 := i2; \n msgs[index].length := 1;\n"^
sprintf " endif;\n"^
sprintf " num:=index;\n msg:=msgs[index];\n end;\n\n";
end;
|`Senc(m1,symk) -> let mAtoms = getAtoms m1 in
let condition =
match symk with