|
|
Line 1,610: |
Line 1,610: |
|
console.log(enc); |
|
console.log(enc); |
|
console.log(dec);</lang> |
|
console.log(dec);</lang> |
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
'''Works with gojq, the Go implementation of jq''' |
|
⚫ |
<lang jq>def vigenere(text; key; encryptp): |
|
⚫ |
# retain alphabetic characters only |
|
⚫ |
|
|
⚫ |
ascii_upcase | explode | map(select(65 <= . and . <= 90)) | [., length]; |
|
⚫ |
(text | n) as [$xtext, $length] |
|
⚫ |
| (key | n) as [$xkey, $keylength] |
|
⚫ |
| reduce range(0; $length) as $i (null; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
then (($xtext[$i] + $xkey[$ki] - 130) % 26) + 65 |
|
⚫ |
else (($xtext[$i] - $xkey[$ki] + 26) % 26) + 65 |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
| ., vigenere($encoded; $key; false) ; |
|
|
|
|
⚫ |
"Beware the Jabberwock, my son! The jaws that bite, the claws that catch!" |
|
⚫ |
| (., example("VIGENERECIPHER")), |
|
⚫ |
|
|
⚫ |
(., example("ROSETTACODE"))</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! |
|
⚫ |
WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY |
|
⚫ |
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH |
|
|
|
|
⚫ |
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! |
|
⚫ |
SSOEKXTJSMESPWVPHCMABWFBLLXCAYGWLRHTMMXTJSFPRKKXATTEOWGY |
|
⚫ |
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre> |
|
|
|
|
|
=={{header|Jsish}}== |
|
=={{header|Jsish}}== |
Line 1,653: |
Line 1,690: |
|
<pre>prompt$ jsish -u vigenereCipher.jsi |
|
<pre>prompt$ jsish -u vigenereCipher.jsi |
|
[PASS] vigenereCipher.jsi</pre> |
|
[PASS] vigenereCipher.jsi</pre> |
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
'''Works with gojq, the Go implementation of jq''' |
|
⚫ |
<lang jq>def vigenere(text; key; encryptp): |
|
⚫ |
# retain alphabetic characters only |
|
⚫ |
|
|
⚫ |
ascii_upcase | explode | map(select(65 <= . and . <= 90)) | [., length]; |
|
⚫ |
(text | n) as [$xtext, $length] |
|
⚫ |
| (key | n) as [$xkey, $keylength] |
|
⚫ |
| reduce range(0; $length) as $i (null; |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
then (($xtext[$i] + $xkey[$ki] - 130) % 26) + 65 |
|
⚫ |
else (($xtext[$i] - $xkey[$ki] + 26) % 26) + 65 |
|
⚫ |
|
|
⚫ |
|
|
|
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
|
|
⚫ |
| ., vigenere($encoded; $key; false) ; |
|
|
|
|
⚫ |
"Beware the Jabberwock, my son! The jaws that bite, the claws that catch!" |
|
⚫ |
| (., example("VIGENERECIPHER")), |
|
⚫ |
|
|
⚫ |
(., example("ROSETTACODE"))</lang> |
|
⚫ |
|
|
⚫ |
|
|
⚫ |
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! |
|
⚫ |
WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY |
|
⚫ |
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH |
|
|
|
|
⚫ |
Beware the Jabberwock, my son! The jaws that bite, the claws that catch! |
|
⚫ |
SSOEKXTJSMESPWVPHCMABWFBLLXCAYGWLRHTMMXTJSFPRKKXATTEOWGY |
|
⚫ |
BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre> |
|
|
|
|
|
|
|
|
|
|
|
|