Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,28 @@
class Chao{
var [const private] lAlphabet = "HXUCZVAMDSLKPEFJRIGTWOBNYQ",
rAlphabet = "PTLNBQDEOYSFAVZKGJRIHWXUMC";
fcn encode(text){ code(text,encodeL); }
fcn decode(text){ code(text,decodeL); }
// reset alphabets each [en|de]code and maintain re-entrancy
fcn code(text,f){ text.apply(f,Data(Void,lAlphabet),Data(Void,rAlphabet)) }
fcn [private] encodeL(letter,left,right){ // encode a letter
index:=right.index(letter);
enc :=left[index].toChar();
permute(left,right,index);
println(left.text," ",right.text," ",index);
enc
}
fcn [private] decodeL(letter,left,right){ // decode a letter
index:=left.index(letter);
dec :=right[index].toChar();
permute(left,right,index);
dec
}
fcn [private] permute(left,right,index){
left.append(left.pop(0,index)); // rotate index times
left.insert(13,left.pop(1)); // rotate [1..13] once
right.append(right.pop(0,index+1)); # rotate index+1 times, idx==25==noop
right.insert(13,right.pop(2)); // rotate [2..13] once
}
}

View file

@ -0,0 +1,9 @@
plainText:="WELLDONEISBETTERTHANWELLSAID";
println("The original plaintext is : ",plainText);
println("\nThe left and right alphabets after each permutation"
" during encryption are:");
cipherText:=Chao.encode(plainText);
println("\nThe ciphertext is : ",cipherText);
plainText2:=Chao.decode(cipherText);
println("\nThe recovered plaintext is : ",plainText2);