ØAṙ13żµ;ŒlZyɠ
Try it online!
Still one byte away from 05AB1E ლ(ಠ益ಠლ). Weirdest way I've ever defined a Jelly link, but it works. Takes the string via STDIN (no shorter than taking an ARGV, in this instance)
How it works
ØAṙ13żµ;ŒlZyɠ - Main link. No arguments
ØA - Yield the upper case alphabet ["A", "B", ... "Y", "Z"]
ṙ13 - Rotate by 13 units left ["N", "O", ... "L", "M"]
ż - Zip with alphabet. Call this X [["N", "A"], ... ["M", "Z"]]
µ - Begin a monadic chain with X as argument
Œl - X lowercased [["n", "a"], ... ["m", "z"]]
; - Concatenate with X [["N", "A"], ... ["m", "z"]]
Z - Transpose rows and columns [["N", ... "m"], ... ["A", ... "z"]]
ɠ - Yield a line from STDIN. Call this Y "Hello, World!"
y - Transliterate Y based on the mapping in Y "Uryyb, Jbeyq!"
A lot of the work here is done by the y
atom. This is a dyad whose arguments are broken up as follows:
- Left argument: A two element array, consisting of the following elements:
- Characters to be changed from.
- Characters to be changed into.
- Right argument: Character array to transliterate
This is a good example of how it works.
In the right argument (the character array), it replaces each occurrence of a key in the left argument (the mapping) with the corresponding result. Any characters that aren't a key are just left alone.
One of the key things to grasp is that y
doesn't take the mapping in [key, result]
pairs. Instead, it takes the list as a transposition of these pairs, so the pairs
[['a', 'b'], ['c', 'd'], ['e', 'f']]
to translate a
to b
, c
to d
etc. would be represented as
[['a', 'c', 'e'], ['b', 'd', 'f']]
in order to use y
. When using y
, if no result is produced and STDERR has an error message, try prepending a Z
, to make Zy
, and see if that works.
1and make sure they don't use rot13 in standard library? like the PHP one – Ming-Tang – 2011-01-28T02:45:06.397
2Don't you mean A-Za-z (to count both upper- and lower-case) ? – Joey Adams – 2011-01-27T21:33:59.870
3Tags are used to categorize questions and help search similar questions. The [tag:cryptography] tag (from Greek kryptós, "hidden, secret"; and graphein, "writing") in particular is for encryption and decryption problems. All encryption and decryption, not only those that are secure for modern applications. – Angs – 2016-12-03T10:33:50.787
1@Nakilon If you call arithmetic math, then you're probably also inclined to call spelling writing. I've never seen someone win a spelling bee and get called a writer for it. Just as doing fast arithmetic doesn't make you a mathematician. – Cruncher – 2013-12-03T21:40:05.437
@Nakilon: (Re retag.) rot13 is not cryptography (at least not in the modern sense of the word). – Chris Jester-Young – 2011-01-30T15:18:44.767
5@Chris Jester-Young, it belongs to this category at wikipedia. It's part of cryptography, just not the hardest one. Anyway, I'm not longer following this site. Community dissapointed me. Sorry. GL HF. – Nakilon – 2011-01-30T18:59:53.360
@Nakilon: That is like saying XOR (for a fixed value) is encryption. That's ludicrous. Also, sorry to hear you're leaving. – Chris Jester-Young – 2011-01-30T19:01:23.810
17Saying xor is not encryption is like saying a+b is not math. – Nakilon – 2011-01-30T19:02:40.080
2@Nakilon: Actually, I call that arithmetic, not mathematics. *shrug* – Chris Jester-Young – 2011-01-30T19:04:14.573
2@Chris Jester-Young, I thought arithmetic is part of math ,.) – Nakilon – 2011-01-30T19:05:56.130
2@ChrisJester-Young: The only encryption which is provably safe, the one-time pad, is exactly the original message XORed with a fixed value (of the same length as the message). – celtschk – 2014-04-10T20:01:36.357
3The problem shouldn't be a tag, so I removed ROT13, just an FYI – Nick Berardi – 2011-01-27T21:18:01.313
1xor is encryption. rot13 is encoding, as is caesar-chiffre. (chiffre = encoding) – oenone – 2011-08-15T12:56:57.130