ADFGVX cipher: Difference between revisions

Content deleted Content added
Midaz (talk | contribs)
Added Uiua solution
Midaz (talk | contribs)
→‎{{header|Uiua}}: Changed the algorithm
 
Line 3,071:
Quick and simple solution for demonstration purposes.
<syntaxhighlight lang="uiua">
A ← ↯∞_2⊞⊟."ADFGVX"
# Implementation of the ADFGVX cipher
P ← ⊏⍏[.√⧻⍥⚂].Shuffle"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
# https://rosettacode.org/wiki/ADFGVX_cipher
 
Shuffle ← ⊏⍏[⍥⚂]⧻.
P ← ↯[.√⧻].Shuffle"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
K ← "PACKHORSE"
ADsSw⊞⊟.⊜□≠"ADFGVX ".
Polybius ← setinv(/⊂⊡≡(⊚⌕):⊙:¤P A|⊏:P≡(⊢⊚⌕)⊙¤∩≡□↯∞_2:A)
 
SortByK ← setinv(⊏⍏⟜(⍉⬚" "↯⊟∞⧻)K|▽≠" "./⊂⍉⊏⍏⍏K)
Str ← setinv(/$"_ _"Sw/⊂≡(⊂:" ")|≡(⊢°□◇⬚" "↯⊟∞)/↥≡◇⧻.Sw)
Pt ← "ATTACKAT1200AM"
&p $"Key = _\nPolybius:\n_\nPlaintext = _"K↯⊟.√⧻.P Pt
 
&p $"KeyCrypttext = _\nPolybius:\n_\nPlaintext". = _"Str KSortByK PPolybius Pt
&p$"Plaintext = _" °Polybius °SortByK °Str
/⊂⊡≡(⊢⊚⌕)Pt ¤P ADs # Find each char in P, map to ADs pair.
/◇(⊂⊂)@ ⊏⍏⟜(⍉⬚@ ↯[∞ ⧻])K # Split over lenK columns, sort those by K, concat.
/◇(⊂⊂)@ ⊜□≠@ . # Clear out spare spaces.
&p $"Crypttext = _" .
 
/↥≡◇⧻.⊜□≠@ . # Find max group len.
≡(⊢°□◇⬚@ ↯[∞ ∘]) # Build (len x num of groups) table.
/⊂⍉⊏⍏⍏K # Unsort by K
▽¬≡(∊@ ).↯∞_2 # Create pairs
⊡:P≡(⊢⊚⌕□):¤≡≡□ADs # Find pos's in ADs, and unmap from P.
&p $"Decrypted plaintext = _"
 
</syntaxhighlight>
 
Line 3,110 ⟶ 3,098:
Plaintext = ATTACKAT1200AM
Crypttext = GFX VVX GXV VGX FFF FVF FVXG FFF GGG
Decrypted plaintextPlaintext = ATTACKAT1200AM
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-ioutil}}