Bifid cipher: Difference between revisions

J
(Created new draft task and added a Wren solution.)
 
(J)
Line 61:
[[Playfair_cipher|Playfair cipher]]
<br><br>
=={{header|J}}==
Implementation:<lang J>alpha=. a.{~65+i.26
normalize=. alpha {{ rplc&'JI'(toupper y)([-.-.)m }}
bifid=: {{ m{~_2 (5&#.)\,|:5 5#:m i.normalize y }}
difib=: {{ m{~5#.|:(|.@$$,)5 5#:m i.normalize y }}</lang>
 
Task examples:<lang J>ref1=: ~.normalize alpha
ref2=: 'BGWKZQPNDSIOAXEFCLUMTHYVR'
ref3=: 'PLAYFIREXMBCDGHKNOQSTUVWZ'
 
ref1 bifid 'attack at dawn'
DQBDAXDQPDQH
ref1 difib ref1 bifid 'attack at dawn'
ATTACKATDAWN
ref2 bifid 'flee at once'
UAEOLWRINS
ref2 difib ref2 bifid 'flee at once'
FLEEATONCE
ref2 bifid 'attack at dawn'
EYFENGIWDILA
ref2 difib ref2 bifid 'attack at dawn'
ATTACKATDAWN
ref3 bifid 'The invasion will start on the first of January'
VRSYXSIYTMQVIRSKISLPVLDTCKRTCAIVTMATCEX
ref3 difib ref3 bifid 'The invasion will start on the first of January'
THEINVASIONWILLSTARTONTHEFIRSTOFIANUARY</lang>
 
We could include both I and J by increasing the square size to 64: take all ascii characters in the range from 32 (space) to 126 (tilde). Discard the lower case letters. Discard four other characters. Use the remainder for the square.
 
=={{header|Wren}}==
One way of enabling all 26 letters to be encrypted uniquely would be to use a 6 x 6 Polybius square including the 10 digits. We could then encrypt text using numerals as well.
6,962

edits