Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
procedure main()
|
||||
StraddlingCheckerBoard("setup","HOLMESRTABCDFGIJKNPQUVWXYZ./", 3,7)
|
||||
|
||||
text := "One night. it was on the twentieth of March, 1888. I was returning"
|
||||
write("text = ",image(text))
|
||||
write("encode = ",image(en := StraddlingCheckerBoard("encode",text)))
|
||||
write("decode = ",image(StraddlingCheckerBoard("decode",en)))
|
||||
end
|
||||
|
||||
procedure StraddlingCheckerBoard(act,text,b1,b2)
|
||||
static SCE,SCD
|
||||
case act of {
|
||||
"setup" : {
|
||||
if (b1 < b2 < 10) & (*text = *cset(text) = 28) then {
|
||||
SCE := table("")
|
||||
SCD := table()
|
||||
esc := text[-1] # escape
|
||||
every text[(b1|b2)+1+:0] := " " # blanks
|
||||
uix := ["",b1,b2] # 1st position
|
||||
every c := text[1 + (i := 0 to *text-1)] do # build translation
|
||||
if c ~== " " then # skip blanks
|
||||
SCD[SCE[c] := SCE[map(c)] := uix[i/10+1]||(i%10) ] := c
|
||||
every c := !&digits do
|
||||
SCD[SCE[c] := SCE[esc] || c] := c
|
||||
delete(SCD,SCE[esc])
|
||||
delete(SCE,esc)
|
||||
}
|
||||
else stop("Improper setup: ",image(text),", ",b1,", ",b2)
|
||||
}
|
||||
"encode" : {
|
||||
every (s := "") ||:= x := SCE[c := !text]
|
||||
return s
|
||||
}
|
||||
"decode" : {
|
||||
s := ""
|
||||
text ? until pos(0) do
|
||||
s ||:= \SCD[k := move(1 to 3)]
|
||||
return s
|
||||
}
|
||||
}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue