Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Playfair-cipher/Zkl/playfair-cipher-1.zkl
Normal file
5
Task/Playfair-cipher/Zkl/playfair-cipher-1.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
fcn genKeyTable(key,deadChr){ // deadChr=="Q" or "J"
|
||||
deadChr=deadChr.toUpper();
|
||||
key=key.toUpper().unique() - " " - deadChr;
|
||||
return(key + (["A".."Z"].pump(String) - deadChr - key), deadChr);
|
||||
}
|
||||
24
Task/Playfair-cipher/Zkl/playfair-cipher-2.zkl
Normal file
24
Task/Playfair-cipher/Zkl/playfair-cipher-2.zkl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
fcn playfair(text,keytable){ // text is a-z only
|
||||
keyTable,deadChr:=keytable;
|
||||
text=text.toUpper();
|
||||
text-=text - keyTable; // remove unencodable characters
|
||||
if(deadChr=="Q") text-=deadChr; else text=text.replace("J","I");
|
||||
|
||||
text=text.pump(String,T(Void.Read,1,False),
|
||||
fcn(a,b=""){ if(a==b) a+"X"+b else a+b });
|
||||
if(text.len().isOdd) text+="Z";
|
||||
|
||||
row:='wrap(c){ keyTable.index(c)/5 };
|
||||
col:='wrap(c){ keyTable.index(c)%5 };
|
||||
ltrRight:='wrap(c){ keyTable[(keyTable.index(c) + 1)%25] };
|
||||
ltrBelow:='wrap(c){ keyTable[(keyTable.index(c) + 5)%25] };
|
||||
ltrAt:='wrap(r,c) { keyTable[r*5 + c] };
|
||||
|
||||
text.pump(String, Void.Read, //-->digraph
|
||||
'wrap(a,b){
|
||||
if((ra:=row(a))==(rb:=row(b))) return(ltrRight(a) + ltrRight(b));
|
||||
if((ca:=col(a))==(cb:=col(b))) return(ltrBelow(a) + ltrBelow(b));
|
||||
return(ltrAt(ra,cb) + ltrAt(rb,ca));
|
||||
})
|
||||
.pump(String,Void.Read,"".create.fp(" ")).strip(); // insert blanks
|
||||
}
|
||||
16
Task/Playfair-cipher/Zkl/playfair-cipher-3.zkl
Normal file
16
Task/Playfair-cipher/Zkl/playfair-cipher-3.zkl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fcn decodePF(text,keyTable){
|
||||
keyTable,_=keyTable;
|
||||
text-=" ";
|
||||
row:='wrap(c){ keyTable.index(c)/5 };
|
||||
col:='wrap(c){ keyTable.index(c)%5 };
|
||||
ltrLeft:='wrap(c){ keyTable[(keyTable.index(c) - 1)%25] };
|
||||
ltrUp:='wrap(c){ n:=keyTable.index(c) - 5; if(n<0)n+=25; keyTable[n%25] };
|
||||
ltrAt:='wrap(r,c){ keyTable[r*5 + c] };
|
||||
text.pump(String,Void.Read, //-->digraph
|
||||
'wrap(a,b){
|
||||
if((ra:=row(a))==(rb:=row(b))) return(ltrLeft(a) + ltrLeft(b));
|
||||
if((ca:=col(a))==(cb:=col(b))) return(ltrUp(a) + ltrUp(b));
|
||||
return(ltrAt(ra,cb) + ltrAt(rb,ca));
|
||||
})
|
||||
.pump(String,Void.Read,"".create.fp(" ")).strip(); // insert blanks
|
||||
}
|
||||
6
Task/Playfair-cipher/Zkl/playfair-cipher-4.zkl
Normal file
6
Task/Playfair-cipher/Zkl/playfair-cipher-4.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
msg:="Hide the gold in the tree stump!!!";
|
||||
keyTable:=genKeyTable("playfair example");
|
||||
msg.println();
|
||||
e:=playfair(msg,keyTable); e.println();
|
||||
decodePF(e,keyTable).println();
|
||||
playfair("XX",keyTable).println() : decodePF(_,keyTable).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue