Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Substitution-cipher/Picat/substitution-cipher-1.picat
Normal file
40
Task/Substitution-cipher/Picat/substitution-cipher-1.picat
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
main =>
|
||||
S = "The quick brown fox jumped over the lazy dog",
|
||||
cypher(S,E), % encrypt
|
||||
println(E),
|
||||
|
||||
cypher(D, E), % decrypt
|
||||
println(D),
|
||||
|
||||
S == D,
|
||||
println(ok).
|
||||
|
||||
cypher(O, S) :-
|
||||
nonvar(O),
|
||||
var(S),
|
||||
sub_chars(O,S).
|
||||
cypher(O, S) :-
|
||||
nonvar(S),
|
||||
var(O),
|
||||
sub_chars(O,S).
|
||||
|
||||
base("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ").
|
||||
subs("VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWob LkESYMTN").
|
||||
|
||||
sub_chars(Original,Subbed) :-
|
||||
base(Base),
|
||||
subs(Subs),
|
||||
maplist($sub_char(Base,Subs),Original,Subbed).
|
||||
|
||||
sub_char([Co|_],[Cs|_],Co,Cs) :- !.
|
||||
sub_char([_|To],[_|Ts], Co, Cs) :- sub_char(To,Ts,Co,Cs).
|
||||
|
||||
maplist(Goal, List1, List2) :-
|
||||
maplist_(List1, List2, Goal).
|
||||
|
||||
maplist_([], X, _) :- X = [].
|
||||
maplist_([Elem1|Tail1],
|
||||
[Elem2|Tail2],
|
||||
Goal) :-
|
||||
call(Goal, Elem1, Elem2),
|
||||
maplist_(Tail1, Tail2, Goal).
|
||||
23
Task/Substitution-cipher/Picat/substitution-cipher-2.picat
Normal file
23
Task/Substitution-cipher/Picat/substitution-cipher-2.picat
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
main =>
|
||||
S = "The quick brown fox jumped over the lazy dog!!!",
|
||||
E = encrypt(S),
|
||||
println(E),
|
||||
D = decrypt(E),
|
||||
println(D),
|
||||
|
||||
D == S,
|
||||
println(ok),
|
||||
nl.
|
||||
|
||||
encrypt(L) = [EncryptMap.get(C,C) : C in L] =>
|
||||
base(Base),
|
||||
subs(Subs),
|
||||
EncryptMap = new_map([B=S : {B,S} in zip(Base,Subs)]).
|
||||
|
||||
decrypt(L) = [DecryptMap.get(C,C) : C in L] =>
|
||||
base(Base),
|
||||
subs(Subs),
|
||||
DecryptMap = new_map([S=B : {B,S} in zip(Base,Subs)]).
|
||||
|
||||
base("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ").
|
||||
subs("VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWob LkESYMTN").
|
||||
Loading…
Add table
Add a link
Reference in a new issue