Comments on Beaver Code Decryption
Parent
Beaver Code Decryption
Credit
This challenge is taken with permission from https://www.mysterytwisterc3.org/en/challenges/level-1/beaver-code
Description
The encryption method is as follows:
The plaintext is divided into two halves, odd positions and even positions.
Example: 'CRYPTO' -> ['CYT','RPO']
This is then applied recursively to both halves, until each part is two letters or less. The parts are then merged.
'CRYPTO' -> ['CYT','RPO'] -> [['CT','Y'], ['RO','P']] -> 'CTYROP'
Challenge
Given a string encrypted with this method, decrypt it.
Valid input formats: ['CTYROP'], 'CTYROP'
Test cases
CTYROP -> CRYPTO
EOYCTNNPRI -> ENCRYPTION
RUOENFSEAFMRDHT -> RANDOMSTUFFHERE
Note: the encryption of the last test case is the same as the decryption, make sure you're decrypting!
BQN, 24 bytesSBCS ``` {g⊔⁼𝕊¨ …
4y ago
Solutions by ngn https://ch …
4y ago
[Jelly], 9 bytes ŒHß¹Ḋ? …
4y ago
APL(Dyalog Unicode), 34 29 byt …
3y ago
APL(Dyalog Extended), 32 bytes …
4y ago
[Husk], 8 bytes ΣTm?I₀ε …
4y ago
Post
APL(Dyalog Unicode), 34 29 bytes SBCS
Saved 5 bytes thanks to Razetime!
{2>s←⌈2÷⍨≢⍵:⍵⋄,⍉↑∇¨s(↑,⍥⊂↓)⍵}
{2>s←⌈2÷⍨≢⍵:⍵⋄,⍉↑∇¨s(↑,⍥⊂↓)⍵}
{ } ⍝ Define a dfn taking argument ⍵
s→ ⍝ s will be the size of one half of ⍵
≢⍵ ⍝ Length of ⍵
2÷⍨ ⍝ Divided by two
⌈ ⍝ Rounded up
2> ⍝ If s is 1 (⍵ has 1 or 2 elements):
:⍵ ⍝ Just return ⍵
⋄ ⍝ Otherwise
s(↑ ↓)⍵ ⍝ Train with first s elements of ⍵ on left
⍝ And second half of ⍵ on right
⍥ ⍝ For both halves
⊂ ⍝ Box them
, ⍝ Join into vector
∇¨ ⍝ Run this function again on each half
↑ ⍝ Turn into a character matrix
⍉ ⍝ Transpose
, ⍝ Concatenate to interleave them together
1 comment thread