Substitution cipher: Difference between revisions

(→‎{{header|Scala}}: Add Ruby; with Reve quote like Scala)
Line 1,024:
<pre>Encoded: "uTu]cu]b3Qu]<d]Id]...><K<,<Kd|]6KMbuTi
Decoded: Here we have to do is... Substitution Cipher.</pre>
 
=={{header|jq}}==
{{trans|Wren}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>def key:
"]kYV}(!7P$n5_0i R:?jOWtF/=-pe'AD&@r6%ZXs\"v*N[#wSl9zq2^+g;LoB`aGh{3.HIu4fbK)mU8|dMET><,Qc\\C1yxJ";
 
def encode:
(key|explode) as $key
| explode as $exploded
| reduce range(0;length) as $i ([];
. + [$key[ $exploded[$i] - 32]] )
| implode;
def decode:
(key|explode) as $key
| explode as $exploded
| reduce range(0;length) as $i ([];
$exploded[$i] as $c
| . + [ $key | index($c) + 32] )
| implode ;
 
def task:
"The quick brown fox jumps over the lazy dog, who barks VERY loudly!"
| encode as $encoded
|"Encoded: \($encoded)",
"Decoded: \($encoded|decode)" ;
 
task</lang>
{{out}}
<pre>
Encoded: 2bu]E,KHm].Tdc|]4d\]),8M>]dQuT]<bu]U31C]Idf_]cbd].3Tm>]+ZzL]Ud,IUCk
Decoded: The quick brown fox jumps over the lazy dog, who barks VERY loudly!
</pre>
 
 
=={{header|Julia}}==
2,460

edits