The Straddling Checkerboard is a method for converting letters to numbers and was part of a pencil an paper cipher known as VIC

To convert letters to numbers first you have to make a checkboard like this:

    0   1   2   3   4   5   6   7   8   9
---------------------------------------
E   T       A   O   N       R   I   S
2 | B   C   D   F   G   H   J   K   L   M
6 | P   Q   #   U   V   W   X   Y   Z   .


Is a 10 x 3 table filled with 28 different simbols and two blanks on the first row.

The labels of second and third row are the position of the blanks on the first one.

To cipher a message you have to replace each letter with the column label. If it is not on the first row, prepend row label:

G -> 24
O -> 4
L -> 28
F -> 23


The extra simbols # and . are used to escape numbers and to indicate full-stop.

## Input:

• 0 to 26 unsorted unique letters (key)
• 4 digits, #1 != #2 and #3 != #4
• Alphanumeric message to be encoded

## Output:

• Digits representing the encoded message

## Implementation:

The table will be filled with the 26 character recived by input. If lengh is less than 26, the remaining spaces will be filled with the missing letters in alphabetical order. The first two integers represent the blank spaces on the first row (and labels for second and third row).Next two integers represent the position of # and . on the third row.

### Example:

Input: codeglf , 4 6 8 9 , "programming puzzles are gr8."

Yields this table:

   0 1 2 3 4 5 6 7 8 9
-------------------
c o d e   g   l f a
4| b h i j k m n p q r
6| s t u v w x y z # .


Output: 47491549945454246547727777637094935496886869

Note1: Spaces are not encoded and not included in the output.

Note2: Original message may contain letters, numbers, spaces and . (assume same capitalisation as the key)

Note3: If there is a number in the original message you have to output the corresponding code number for # followed by the number then another # code (68 in the example) and then continue with the letters.

### Example2:

Input: toearly , 2 8 6 1 , "wake up at 06.am"

   0 1 2 3 4 5 6 7 8 9
-------------------
t o   e a r l y   b
2| c d f g h i j k m n
8| p . q s u v # w x z

w  a  k e  u  p a t  # 0 6  #  . a  m
87 4 27 3 84 80 4 0 86 0 6 86 81 4 28


Output: 87427384804086068681428

This is the complete VIC cipher question.

• In the example . is encoded as 69 May 30, 2017 at 18:32
• Under "Implementation", it might be worth reiterating that the first 2 integers are also used as the row labels. Also, it looks like you might be missing the gr before the 8 from your output, if I'm reading it right. May 30, 2017 at 18:48
• It looks to me like your output is wrong. It decodes into 'programmingpldllllvlcaregr8.' May 30, 2017 at 20:51
• The first half is encoded with 4 7 8 9 but the last half uses 4 6 8 9.
– Neil
May 30, 2017 at 23:36

## JavaScript (ES6), 236 bytes

(k,s,t,h,d,m)=>m.replace(/./g,c=>1/c?c>' '?''+t+h+c:'':(c=a.indexOf(c))>9?''+(c>19?t:s)+c%10:c,l=[...'zyxwvutsrqponmlkjihgfedcba'].filter(c=>k.search(c)<0),i=0,a=[...Array(30)].map((_,n)=>n-s&&n-t&&n-h-20?n-d-20?k[i++]||l.pop():'.':''))


Creates the checkboard a (except for the #, which is special-cased), then replaces letters and . in the message with the appropriately translated index while digits are prefixed with the code for #.

# PHP>=7.1, 226 Bytes

for([,$c,$a,$b,$d,$e,$t]=$argv,$c.=join(preg_grep("#[^$c]#",range(a,z)));$p<30;)$x[in_array($y=["",$a,$b][$p/10].$p++%10,[$a,$b,$b.$d,$b.$e])?"__#."[$m++]:$c[$i++]]=$y;for(;a&$w=$t[$k++];)echo is_numeric($w)?$x["#"].$w:$x[$w];


Online Version

Expanded

for([,$c,$a,$b,$d,$e,$t]=$argv #short variables in input array ,$c.=join(preg_grep("#[^$c]#",range(a,z))) # join the rest of alphabet ;$p<30;) # loop 30 times
$x[in_array($y=["",$a,$b][$p/10].$p++%10 # is actual position reserved?
,[$a,$b,$b.$d,$b.$e]) # reserved positions
?"__#."[$m++] # set reserved positions with chars underscore instead spaces to avoid encoding :$c[$i++]] # set alpabetic characters =$y; # make encoding array
for(;a&$w=$t[$k++];) # loop through string which shall be encoded echo is_numeric($w)
?$x["#"].$w # printing for digits
:$x[$w]; #printing for the other characters


# R, 286 281 261 bytes

Bit horrible looking and I am sure there is room for improvement, but I wanted to make sure I was doing it correctly before really getting into it.

Have changed it a bit to use 2 arrays and handle the numbers differently. Hopefully this makes it easier to golf.

Implemented as an unnamed function that take 4 parameters - k the key for the table - x a vector containing the row name integers - y a vector containing the "#",'.' locations - s the string to encode

function(k,x,y,s){W=which
S=strsplit
P=paste0
L=letters
m=rep(NA,40)
m[c(1:10,x+11,y+31)]=c(0:9,'','','#','.')
m[is.na(m)]=c(d<-el(S(k,'')),L[-W(L%in%d)])
i=t(outer(c(P(x,y),'',x),0:9,P));cat(sapply(el(S(gsub(' ','',s),'')),function(x)i[W(m==x)]),sep='')}


Try it online!

I have loaded the library methods in TIO example to get el() to work, however this is not required on my version of R.