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,24 @@
procedure main()
ptext := "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
write("Key = ",ekey := "VIGENERECIPHER")
write("Plain Text = ",ptext)
write("Normalized = ",GFormat(ptext := NormalizeText(ptext)))
write("Enciphered = ",GFormat(ctext := Vignere("e",ekey,ptext)))
write("Deciphered = ",GFormat(ptext := Vignere("d",ekey,ctext)))
end
procedure Vignere(mode,ekey,ptext,alpha) #: Vignere cipher
/alpha := &ucase # default
if *alpha ~= *cset(alpha) then runerr(205,alpha) # no dups
alpha ||:= alpha # unobstructed
every ctext:="" & p:=ptext[i := 1 to *ptext] & k:=ekey[(i-1)%*ekey+1] do
case mode of {
"e"|"encrypt":
ctext||:=map(p,alpha[1+:*alpha/2],alpha[find(k,alpha)+:(*alpha/2)])
"d"|"decrypt":
ctext||:=map(p,alpha[find(k,alpha)+:(*alpha/2)],alpha[1+:*alpha/2])
default: runerr(205,mode)
}
return ctext
end

View file

@ -0,0 +1,13 @@
link strings
procedure NormalizeText(ptext,alpha) #: text/case classical crypto helper
/alpha := &ucase # default
if &lcase === (alpha := cset(alpha)) then ptext := map(ptext) # lower
if &ucase === alpha then ptext := map(ptext,&lcase,&ucase) # upper
return deletec(ptext,&cset--alpha) # only alphas
end
procedure GFormat(text) #: 5 letter group formatting helper
text ? (s := "", until pos(0) do s ||:= " " || move(5)|tab(0))
return s[2:0]
end