ROT-13 transform standard input

35

5

The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible.

Any language that can read and write standard streams is fair game.

MiffTheFox

Posted 2011-01-27T21:11:06.677

Reputation: 631

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

Answers

25

Bash, 23 bytes

Canonical 23-character answer:

tr A-Za-z N-ZA-Mn-za-m

Chris Jester-Young

Posted 2011-01-27T21:11:06.677

Reputation: 4 464

@Nabb: No, to me it looks as if he's wrong. Or may you show an example? – user unknown – 2011-02-06T05:56:23.457

2@user unknown: Type in [\\]^_\`` in the input. It will come back asNOPQRSrather than[\]^_``, at least in the version of tr I have. (Those are the six characters in ASCII that lie between Z and a. Obviously, all other characters will work correctly.) – Chris Jester-Young – 2011-02-06T07:07:00.650

You're right, I see. – user unknown – 2011-02-06T12:47:49.093

1I'm without access to bash at the moment, but I think this should work: tr A-za-m N-ZA-z (16 chars) – Nabb – 2011-02-02T07:24:31.253

2@Nabb: Nice to see you, GolfScript-meister! :-D I think your solution here would break the stipulation that "All characters besides A-Z should be copied to the output verbatim". – Chris Jester-Young – 2011-02-02T12:07:23.897

@Chris: Yep, looks like you're right. – Nabb – 2011-02-03T02:22:48.120

20

Bash - 5 chars

rot13

 

gnibbler

Posted 2011-01-27T21:11:06.677

Reputation: 14 170

8Which bash-version? I don't have a build-in rot13. bash --version GNU bash, Version 4.0.33(1)-release (i486-pc-linux-gnu) – user unknown – 2011-02-06T05:21:58.473

12I'd have submitted this as rot13 - 0 chars... ;) – boothby – 2013-03-09T18:10:59.387

18Two downvotes so far (with no comments), but no downvotes for the question. I assume that means it's ok to ask trivial codegolfs but not to give the trivial answer. Harder codegolfs please! – gnibbler – 2011-01-30T20:49:36.540

1Sorry but your not golfing here your running an application that does it for you and there for you not using bash your using the application 'rot13' however i did not downvote – Martin Barker – 2019-02-27T17:00:58.490

3rot13 is not in coreutils, so this isn't a bash solution or a bash+coreutils solution. – Chris – 2019-02-27T17:53:06.817

2'tis coreutils my friend, not Bash – TheDoctor – 2014-03-17T00:18:26.480

4erm... no. my bash (Ubuntu 13.10) says "command not found, you can install this program by sudo apt-get install bsdgames" – None – 2014-04-09T17:43:40.517

17

Python 2, 34 bytes

print raw_input().encode('rot13')

Juan

Posted 2011-01-27T21:11:06.677

Reputation: 2 738

16I've used them in every code golf I took part in... Also if using python's standard lib is cheating, how is using tr not? – Juan – 2011-01-27T21:27:40.167

9@Glenn, I think library functions are fair game. It's up to the golf question to be interesting enough to not be in anyone's library or to specifically exclude. – gnibbler – 2011-01-28T02:09:41.887

1@Juan: There's no real "hard line", but a lot of it is about how specific the library is. Using transliteration to carry out ROT13 is fine, using the ROT13 builtin is cheating (or at best, a "joke solution"). – Anon. – 2011-01-27T21:33:46.223

3@Anon In any case, it's an anwser you just ignore.. It's not off target, there's not any rules set by the OP nor by the community. Sure, maybe mine is not an award winning solution, like the one using tr that kicks ass. But it's not a joke, I'm leveraging the power of python to reduce the count, just like any other would do. – Juan – 2011-01-27T21:37:13.153

@Juan I'm just saying that pretty much every code-golf thing I've ever done specified that you cannot use built-in libraries that are specifically designed to solve the solution for you. – Glenn Nelson – 2011-01-27T23:30:05.890

2@Glenn: on the contrary, I have never seen a code-golf thing that say so. Neither do codegolf.com, golf.shinh.org or SPOJ SHORTEN. – hallvabo – 2011-01-27T23:36:34.930

See my comment on the other Python solution. raw_input() gives only one line. – Alexandru – 2011-01-27T23:58:22.503

1-1 I think it is cheating that you are using a built in library. – Glenn Nelson – 2011-01-27T21:23:14.740

15

Befunge - 7x30 = 210 6x26 = 156 characters

New streaming version that supports both upper and lower case and should support unlimited input.

v,<               <<     <
  ^-4-9<    >:"A"\`|
     >:"a"\`|     #>:"Z"`|
>~:0`| #    >:"z"`|
,    @ |    <`"m":<v`"M":<
^  +4+9<    ^      <

The old version

This stores the values inside its own source code. Really shows off how horrible it is to try and output stored values in the same order that you receive them. Only supports lowercase characters.

vp0p11:+1g11<      < <
v                    ^-4-9<
v    >:"a"\`|>:"z"`|>:"m"`|
>~:0`|      >^     >^#
                     ^+4+9<
     >$011g1+0p>12g1+:12p0g:v
               ^           ,_@

I'm not sure exactly what limitations this has, using http://www.quirkster.com/iano/js/befunge.html as the interpreter it does appear to break with large inputs.

Nemo157

Posted 2011-01-27T21:11:06.677

Reputation: 1 891

You can remove the whitespace at the end of lines. – Zacharý – 2017-12-31T18:59:29.493

10

vim, 5 keystrokes

Assuming normal mode and that the text is already written in the buffer:

ggg?G

Or, fallowing vimgolf's conventions:

g?GZZ

You can also invoke it as a terminal command, something like this:

$ vim -c 'norm g?G' -
< your text here ...
... multiple lines if you want ...
... terminate input with ctrl+D on a blank line >

I guess the latter would count as a "program" of 8 characters (norm g?G)

daniero

Posted 2011-01-27T21:11:06.677

Reputation: 17 193

norm g?G is short for normal g?G that makes 8 chars. – Patrick Oscity – 2014-09-04T15:23:19.917

I think you can safely assume to start out on line 1, so the first gg can be left off. I would say 3 keystrokes when the file is open. – Patrick Oscity – 2014-09-04T15:24:23.710

1If we use vimgolf's conventions (you start in a vanilla vim having just opened the file, but need to save and quit) we also get 5 (g?GZZ). – FireFly – 2014-10-30T21:53:10.017

10

Ruby - 60 57 38 37 chars

Edit: And just realised Ruby strings have a tr method.

puts$<.read.tr'A-Za-z','N-ZA-Mn-za-m'

Test

input = "The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible.

Any language that can read and write standard streams is fair game."

output = `echo '#{input}' | ruby golf-rot13.rb`

puts "Input:"
puts input
puts "-------"
puts "Output:"
puts output

Gives:

Input:
The challenge: To read an input of arbitrary length and produce the ROT13 of the input. All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible.

Any language that can read and write standard streams is fair game.
-------
Output:
Gur punyyratr: Gb ernq na vachg bs neovgenel yratgu naq cebqhpr gur EBG13 bs gur vachg. Nyy punenpgref orfvqrf N-M fubhyq or pbcvrq gb gur bhgchg ireongvz, naq pnfr fubhyq or cerfreirq vs cbffvoyr.

Nal ynathntr gung pna ernq naq jevgr fgnaqneq fgernzf vf snve tnzr.

Nemo157

Posted 2011-01-27T21:11:06.677

Reputation: 1 891

1Essentially the same but 35 characters: puts gets.tr'A-Za-z','N-ZA-Mn-za-m'. – Michael Kohl – 2011-03-13T23:43:47.610

@Michael: Except gets only returns the first line, using $<.read reads until EOF. The question doesn't say anything about whether the input can contain new lines so I just erred on the side of caution. – Nemo157 – 2011-03-14T00:22:22.897

Fair enough, but since the exercise specification only mentioned "arbitrary length" but said nothing about newlines, I'd rather err on the side of brevity in codegolf ;-) – Michael Kohl – 2011-03-14T07:32:37.397

You don't need the space after puts, and 'A-z' is a shortcut for 'A-Za-z' – Ventero – 2011-02-02T14:52:34.470

1@Ventro: Thanks, after a bit of testing it seems 'A-z' is actually 'A-Z[\]^_a-z', damn ascii having characters betweenZanda`. – Nemo157 – 2011-02-02T20:50:07.297

7

tr/// solution in Perl (39 characters), boilerplate can be removed with -p:

while(<>){y/a-zA-Z/n-za-mN-ZA-M/;print}

Using -p (23 characters including the extra switch):

perl -pe'y/a-zA-Z/n-za-mN-ZA-M/'

Anon.

Posted 2011-01-27T21:11:06.677

Reputation: 1 799

Add 1 char for the p, but please remove the boilerplate! – J B – 2011-02-06T21:04:26.833

7

C - 83 79 characters

main(c,b){while((c=getchar())>=0)b=c&96,putchar(isalpha(c)?b+1+(c-b+12)%26:c);}

Readable version:

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int c, base;

    while ((c = getchar()) >= 0) {
        if (isalpha(c)) {
            base = (c & 96) + 1; /* First letter of the upper or lower case. */
            c = base + (c - base + 13) % 26;
        }
        putchar(c);
    }

    return 0;
}

Joey Adams

Posted 2011-01-27T21:11:06.677

Reputation: 9 929

1Are you including the headers you include in your count? – JPvdMerwe – 2011-01-27T22:18:51.230

@JPvdMerwe: I didn't include any headers in the golfed version, nor did I need to. – Joey Adams – 2011-01-27T22:34:24.777

You can use the coma operator before putchar to remove a pair of braces. – Alexandru – 2011-01-27T23:05:47.970

Could you explain main(c,b)? It's the first time i see this. – Alexandru – 2011-01-27T23:11:49.333

also you can write b=c&96 and move +1 inside putchar. I got your version down to 79 chars. – Alexandru – 2011-01-27T23:17:13.023

@Alexandru: main(c,b) abuses the fact that parameters without types default to int, so you don't have to say int c,b;. This is a pretty common golfing technique for C. Also, thanks for the suggestions. – Joey Adams – 2011-01-27T23:28:38.853

2@Alexandru most C compilers support main with any parameters. Also, the original C standard defines that an argument with no type is an int. Thus you get to declare ints without actually writing int. – Juan – 2011-01-27T23:31:53.880

One more thing: you can get rid of b, replace it with (c&96) and replace c-(c&96) with c%32. Down to 76. – Alexandru – 2011-01-28T01:07:20.190

7

Python (117 bytes)

Here's a Python version that avoids the rot13()-method.

import sys
print"".join([chr(x/32*32+1+(x%32+12)%26if 64<x<91or 96<x<123 else x)for x in map(ord,sys.stdin.read())])

JPvdMerwe

Posted 2011-01-27T21:11:06.677

Reputation: 2 565

raw_input returns one line not all input. – Alexandru – 2011-01-27T23:34:55.647

you need to import sys and use sys.stdin.read(). – Alexandru – 2011-01-27T23:41:12.797

@Alexandru: will do – JPvdMerwe – 2011-01-27T23:46:32.870

7

R, 37 bytes

example("chartr");cat(rot(scan(,"")))

example("chartr") runs the examples for chartr, which includes the rot function, which is ROT13 by default....

mnel

Posted 2011-01-27T21:11:06.677

Reputation: 826

5

Befunge-93, 85 (grid: 41x3=123)

This is an ancient question, but I thought I'd revive it to post a slightly nicer Befunge answer.

#v_~::" "/2%" "*-::"@"`!#v_"Z"#v`#!_1
v> "M"`2*1\-34*1+*+    1:>$!   _:"."-!#@_
>,^

You can test it here. Enter a single character at a time; it terminates upon entering a . character (you can change that by modifying the "." near the right side of the second row). Works with upper and lower case, as well as punctuation, and with no limit to input.

I don't expect this to get a ton of upvotes or anything, but I just wanted to demonstrate how awesome Befunge actually is that you can do a little better than the other answer.

I could probably make it even shorter in Befunge-98.

Kasran

Posted 2011-01-27T21:11:06.677

Reputation: 681

This doesn't work if there is a space in the input. It goes into an infinite loop in the sequence >$! _ because you've got two zeros on the stack at that point when you are expecting a non-zero value. – James Holderness – 2018-01-03T17:30:49.560

You can add my snippet from here to have an inline interpreter, if you want. :)

– Ingo Bürk – 2014-10-30T21:48:24.907

Ooh, I haven't really investigated snippets yet. I'll take a look, thanks! – Kasran – 2014-10-30T22:17:52.877

5

DC (111 108 for the dc itself)

Ok, here it is in (mostly) dc and some sed and od magic to get it into the right format for the code. If you don't count the input thing (echo -n MESSAGE |) it's 160 bytes:

od -An -t dC|sed 's/^\ *//;s/\ \{2,3\}/\n/g'|dc -e'[13+26%]sm[65-lmx65+]su[97-lmx97+]sl[96<b64<dPc]sa[91>c]sd[123>e]sb[lux]sc[llxdd]se[ddddlaxlrx]sy[?z0<y]dsrx'

As a point of interest, the dc programme itself is only a 108 bytes long, shorter than the non-library python version. It even preserves case and punctuation, and beats Javascript in the above submission! If only I could better parse the output of od, or better yet replace it altogether.

EDIT: It's worth noting that the question doesn't indicate a trailing new line 10P which saves me three further bytes.

EDIT 2: There's no specification for the format of the input, so I assume it's taken in as is convenient for my programme :P

Hiato

Posted 2011-01-27T21:11:06.677

Reputation: 731

4

Delphi, 110

var c:Char;begin repeat Read(c);Write(Chr(Ord(c)+(Ord(c in['A'..'M'])-Ord(c in['N'..'Z']))*13));until EOF;end.

PatrickvL

Posted 2011-01-27T21:11:06.677

Reputation: 641

var c:Char;begin repeat Read(c);Write(Chr(Ord(c)+(Ord(c in['A'..'M'])-Ord(c in['N'..'Z']))*13));until EOF;end. saves one character :) – Wouter van Nifterick – 2011-03-13T21:36:36.923

@Wouter van Nifterick : Good spot! I'll update it accordingly – PatrickvL – 2011-03-13T23:28:54.150

4

Haskell, 100 characters

a%b=([a..b]++)
main=interact$map$toEnum.((0%64$78%90$65%77$91%96$110%122$97%109$[123..])!!).fromEnum

MtnViewMark

Posted 2011-01-27T21:11:06.677

Reputation: 4 779

4

PHP - 103 98 80 characters

(not using str_rot13())

<?=preg_replace('#[a-zA-Z]#e','chr(($x=ord("\0"))-$x%32+1+($x%32+12)%26)',`cat`);

Arnaud Le Blanc

Posted 2011-01-27T21:11:06.677

Reputation: 2 286

4

05AB1E, 13 12 bytes

Saved a byte thanks to robbie0630

ADu)øJD2äRJ‡

Try it online!

Explanation

ADu           # push lower-case and uppercase alphabet
   )øJ        # zip, flatten and join, producing aAbB..zZ
      D2äRJ   # split a copy in 2 pieces, reverse and join producing nNoO..mM
           ‡  # translate input by replacing members of the alphabet 
              # with the corresponding member of the rot-13 alphabet
              # implicitly display

Emigna

Posted 2011-01-27T21:11:06.677

Reputation: 50 798

I ran through this with --debug, and it seems like the ˜ is a no-op in this case and can be cut out. – robbie – 2018-02-15T03:31:09.180

@robbie0630: True. No idea why I had that in. Thank you :) – Emigna – 2018-02-15T06:50:15.067

3

C: 69 68 characters

Alright, I know this thread is long dead, but I couldn't stand the (long) C-solution which doesn't even compile on Clang (but does on GCC).

main(c){putchar(isalpha(c=getchar())*((c|32)<110?13:-13)+c);main();}

It is probably almost still squeezable. It certainly was squeezable. And not only was it squeezable, it was possible to make it recursive.

Fors

Posted 2011-01-27T21:11:06.677

Reputation: 3 020

3

Perl6 (54)

$*IN.lines».trans("a..zA..Z"=>"n..za..mN..ZA..M").say

Bruce Armstrong

Posted 2011-01-27T21:11:06.677

Reputation: 161

3

Java 251 chars

public class r{public static void main(String[] a){String s = a[0];for(int i=0;i<s.length();){char c=s.charAt(i++);if(c>='a'&&c<='m')c+=13;else if(c>='n'&&c<='z')c-= 13;else if(c>='A'&&c<='M')c+=13;else if(c>='A'&&c <='Z')c-=13;System.out.print(c);}}}

Clyde Lobo

Posted 2011-01-27T21:11:06.677

Reputation: 1 395

3

Python 3 (107)

Ok, I promise to stop answering this question now, but I felt compelled to beat the DC answer in Python. This probably reflects poorly on me as a person :).

import sys;[print(x.isalpha()and chr((ord(x)&96)+1+(ord(x)%32+12)%26)or x,end='')for x in sys.stdin.read()]

user1011

Posted 2011-01-27T21:11:06.677

Reputation:

3

LispLisp (16,636)

I'm sorry.

((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
  (lisp lisp))
 (((lisp (lisp (lisp (lisp lisp))))
   ((lisp (lisp (lisp lisp)))
    ((lisp (lisp (lisp (lisp lisp))))
     (((lisp (lisp (lisp (lisp lisp))))
       ((lisp (lisp (lisp lisp)))
        (((lisp (lisp (lisp (lisp lisp))))
          (((lisp (lisp (lisp (lisp lisp))))
            ((lisp (lisp (lisp lisp)))
             (lisp (lisp (lisp (lisp lisp))))))
           (((lisp (lisp (lisp (lisp lisp))))
             ((lisp (lisp (lisp lisp)))
              (lisp (lisp (lisp lisp)))))
            (((lisp (lisp (lisp (lisp lisp))))
              ((lisp (lisp (lisp lisp)))
               (lisp (lisp (lisp (lisp lisp))))))
             (((lisp (lisp (lisp (lisp lisp))))
               ((lisp (lisp (lisp lisp)))
                ((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))))
              (lisp (lisp (lisp lisp))))))))
         ((lisp (lisp (lisp lisp)))
          (lisp (lisp (lisp lisp)))))))
      (((lisp (lisp (lisp (lisp lisp))))
        ((lisp (lisp (lisp lisp)))
         (((lisp (lisp (lisp (lisp lisp))))
           (((lisp (lisp (lisp (lisp lisp))))
             ((lisp (lisp (lisp lisp)))
              (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
               ((lisp (lisp (lisp lisp)))
                (lisp (lisp (lisp lisp)))))))
            (((lisp (lisp (lisp (lisp lisp))))
              (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
               ((lisp (lisp (lisp lisp)))
                (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                 ((lisp (lisp (lisp lisp)))
                  ((lisp (lisp (lisp lisp))) (lisp lisp)))))))
             ((lisp (lisp (lisp lisp)))
              (((((lisp (lisp (lisp (lisp lisp))))
                  (((lisp (lisp (lisp (lisp lisp))))
                    ((lisp (lisp (lisp lisp)))
                     (lisp (lisp (lisp (lisp lisp))))))
                   (lisp (lisp (lisp lisp)))))
                 ((((lisp (lisp (lisp (lisp lisp))))
                    ((lisp (lisp (lisp (lisp lisp))))
                     (((lisp (lisp (lisp (lisp lisp))))
                       ((lisp (lisp (lisp lisp)))
                        (lisp (lisp (lisp (lisp lisp))))))
                      (lisp (lisp (lisp lisp))))))
                   (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                    (lisp lisp)))
                  (((lisp (lisp (lisp (lisp lisp))))
                    (((lisp (lisp (lisp (lisp lisp))))
                      ((lisp (lisp (lisp lisp)))
                       (lisp (lisp (lisp (lisp lisp))))))
                     (lisp (lisp (lisp lisp)))))
                   (lisp lisp))))
                (((lisp (lisp (lisp (lisp lisp))))
                  ((lisp (lisp (lisp lisp)))
                   ((lisp (lisp (lisp (lisp lisp))))
                    (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                     ((lisp (lisp (lisp lisp))) (lisp lisp))))))
                 (lisp (lisp (lisp lisp)))))
               ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                 (((lisp (lisp (lisp (lisp lisp))))
                   ((lisp (lisp (lisp lisp)))
                    ((((lisp (lisp (lisp (lisp lisp))))
                       (((lisp (lisp (lisp (lisp lisp))))
                         ((lisp (lisp (lisp lisp)))
                          (lisp (lisp (lisp (lisp lisp))))))
                        (lisp (lisp (lisp lisp)))))
                      (lisp lisp))
                     ((((lisp (lisp (lisp (lisp lisp))))
                        (((lisp (lisp (lisp (lisp lisp))))
                          ((lisp (lisp (lisp lisp)))
                           (lisp (lisp (lisp (lisp lisp))))))
                         (lisp (lisp (lisp lisp)))))
                       (((lisp (lisp (lisp (lisp lisp))))
                         (((lisp (lisp (lisp (lisp lisp))))
                           ((lisp (lisp (lisp lisp)))
                            (lisp (lisp (lisp (lisp lisp))))))
                          (lisp (lisp (lisp lisp)))))
                        (lisp lisp)))
                      (((lisp (lisp (lisp (lisp lisp))))
                        ((lisp (lisp (lisp lisp)))
                         ((lisp (lisp (lisp (lisp lisp))))
                          (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                           ((lisp (lisp (lisp lisp))) (lisp lisp))))))
                       (lisp (lisp (lisp lisp))))))))
                  (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                   ((lisp (lisp (lisp lisp)))
                    ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                      (lisp lisp))
                     (((lisp (lisp (lisp (lisp lisp))))
                       ((lisp (lisp (lisp lisp)))
                        (((lisp (lisp (lisp (lisp lisp))))
                          ((lisp (lisp (lisp lisp)))
                           ((lisp (lisp (lisp (lisp lisp))))
                            (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                             ((lisp (lisp (lisp lisp))) (lisp lisp))))))
                         (lisp (lisp (lisp lisp))))))
                      (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                       (lisp lisp))))))))
                (((lisp (lisp (lisp (lisp lisp))))
                  ((lisp (lisp (lisp lisp)))
                   ((((lisp (lisp (lisp (lisp lisp))))
                      (((lisp (lisp (lisp (lisp lisp))))
                        ((lisp (lisp (lisp lisp)))
                         (lisp (lisp (lisp (lisp lisp))))))
                       (lisp (lisp (lisp lisp)))))
                     (((lisp (lisp (lisp (lisp lisp))))
                       ((lisp (lisp (lisp lisp)))
                        (((lisp (lisp (lisp (lisp lisp))))
                          (((lisp (lisp (lisp (lisp lisp))))
                            ((lisp (lisp (lisp lisp)))
                             (lisp (lisp (lisp (lisp lisp))))))
                           (lisp (lisp (lisp lisp)))))
                         (((lisp (lisp (lisp (lisp lisp))))
                           (((lisp (lisp (lisp (lisp lisp))))
                             ((lisp (lisp (lisp lisp)))
                              (lisp (lisp (lisp (lisp lisp))))))
                            (lisp (lisp (lisp lisp)))))
                          (lisp lisp)))))
                      ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                        (lisp lisp))
                       (((lisp (lisp (lisp (lisp lisp))))
                         (((lisp (lisp (lisp (lisp lisp))))
                           ((lisp (lisp (lisp lisp)))
                            (lisp (lisp (lisp (lisp lisp))))))
                          (lisp (lisp (lisp lisp)))))
                        (lisp lisp)))))
                    (((lisp (lisp (lisp (lisp lisp))))
                      ((lisp (lisp (lisp lisp)))
                       ((lisp (lisp (lisp (lisp lisp))))
                        (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                         ((lisp (lisp (lisp lisp)))
                          ((((lisp (lisp (lisp (lisp lisp))))
                             (((lisp (lisp (lisp (lisp lisp))))
                               ((lisp (lisp (lisp lisp)))
                                (lisp (lisp (lisp (lisp lisp))))))
                              (lisp (lisp (lisp lisp)))))
                            (((lisp (lisp (lisp (lisp lisp))))
                              ((lisp (lisp (lisp lisp)))
                               (((lisp (lisp (lisp (lisp lisp))))
                                 (((lisp (lisp (lisp (lisp lisp))))
                                   ((lisp (lisp (lisp lisp)))
                                    (lisp (lisp (lisp (lisp lisp))))))
                                  (lisp (lisp (lisp lisp)))))
                                (((lisp (lisp (lisp (lisp lisp))))
                                  (((lisp (lisp (lisp (lisp lisp))))
                                    ((lisp (lisp (lisp lisp)))
                                     (lisp (lisp (lisp (lisp lisp))))))
                                   (lisp (lisp (lisp lisp)))))
                                 (lisp lisp)))))
                             ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                               (lisp lisp))
                              (((lisp (lisp (lisp (lisp lisp))))
                                (((lisp (lisp (lisp (lisp lisp))))
                                  ((lisp (lisp (lisp lisp)))
                                   (lisp (lisp (lisp (lisp lisp))))))
                                 (lisp (lisp (lisp lisp)))))
                               (lisp lisp)))))
                           ((lisp (lisp (lisp (lisp lisp))))
                            (((lisp (lisp (lisp (lisp lisp))))
                              ((lisp (lisp (lisp lisp)))
                               (lisp (lisp (lisp (lisp lisp))))))
                             (lisp (lisp (lisp lisp)))))))))))
                     (lisp (lisp (lisp lisp)))))))
                 ((((lisp (lisp (lisp (lisp lisp))))
                    (((lisp (lisp (lisp (lisp lisp))))
                      ((lisp (lisp (lisp lisp)))
                       (lisp (lisp (lisp (lisp lisp))))))
                     (lisp (lisp (lisp lisp)))))
                   (((lisp (lisp (lisp (lisp lisp))))
                     ((lisp (lisp (lisp lisp)))
                      (((lisp (lisp (lisp (lisp lisp))))
                        (((lisp (lisp (lisp (lisp lisp))))
                          ((lisp (lisp (lisp lisp)))
                           (lisp (lisp (lisp (lisp lisp))))))
                         (lisp (lisp (lisp lisp)))))
                       (((lisp (lisp (lisp (lisp lisp))))
                         (((lisp (lisp (lisp (lisp lisp))))
                           ((lisp (lisp (lisp lisp)))
                            (lisp (lisp (lisp (lisp lisp))))))
                          (lisp (lisp (lisp lisp)))))
                        (lisp lisp)))))
                    ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                      (lisp lisp))
                     (((lisp (lisp (lisp (lisp lisp))))
                       (((lisp (lisp (lisp (lisp lisp))))
                         ((lisp (lisp (lisp lisp)))
                          (lisp (lisp (lisp (lisp lisp))))))
                        (lisp (lisp (lisp lisp)))))
                      (lisp lisp)))))
                  (((lisp (lisp (lisp (lisp lisp))))
                    ((lisp (lisp (lisp lisp)))
                     ((lisp (lisp (lisp (lisp lisp))))
                      (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                       ((lisp (lisp (lisp lisp)))
                        (((lisp (lisp (lisp (lisp lisp))))
                          ((lisp (lisp (lisp lisp)))
                           (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                            ((lisp (lisp (lisp lisp)))
                             (lisp (lisp (lisp lisp)))))))
                         (((lisp (lisp (lisp (lisp lisp))))
                           (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                            ((lisp (lisp (lisp lisp)))
                             (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                              ((lisp (lisp (lisp lisp)))
                               ((lisp (lisp (lisp lisp))) (lisp lisp)))))))
                          ((lisp (lisp (lisp lisp)))
                           (((((lisp (lisp (lisp (lisp lisp))))
                               (((lisp (lisp (lisp (lisp lisp))))
                                 ((lisp (lisp (lisp lisp)))
                                  (lisp (lisp (lisp (lisp lisp))))))
                                (lisp (lisp (lisp lisp)))))
                              (((lisp (lisp (lisp (lisp lisp))))
                                ((lisp (lisp (lisp lisp)))
                                 (((lisp (lisp (lisp (lisp lisp))))
                                   (((lisp (lisp (lisp (lisp lisp))))
                                     ((lisp (lisp (lisp lisp)))
                                      (lisp (lisp (lisp (lisp lisp))))))
                                    (lisp (lisp (lisp lisp)))))
                                  (((lisp (lisp (lisp (lisp lisp))))
                                    (((lisp (lisp (lisp (lisp lisp))))
                                      ((lisp (lisp (lisp lisp)))
                                       (lisp (lisp (lisp (lisp lisp))))))
                                     (lisp (lisp (lisp lisp)))))
                                   (lisp lisp)))))
                               ((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                                 (lisp lisp))
                                (((lisp (lisp (lisp (lisp lisp))))
                                  (((lisp (lisp (lisp (lisp lisp))))
                                    ((lisp (lisp (lisp lisp)))
                                     (lisp (lisp (lisp (lisp lisp))))))
                                   (lisp (lisp (lisp lisp)))))
                                 (lisp lisp)))))
                             (((lisp (lisp (lisp (lisp lisp))))
                               ((lisp (lisp (lisp lisp)))
                                ((lisp (lisp (lisp (lisp lisp))))
                                 (((lisp (lisp (lisp (lisp lisp))))
                                   (lisp lisp))
                                  ((lisp (lisp (lisp lisp))) (lisp lisp))))))
                              (lisp (lisp (lisp lisp)))))
                            (((((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
                               (lisp lisp))
                              (((lisp (lisp (lisp (lisp lisp))))
                                ((lisp (lisp (lisp lisp)))
                                 ((lisp (lisp (lisp (lisp lisp))))
                                  (((lisp (lisp (lisp (lisp lisp))))
                                    ((lisp (lisp (lisp lisp)))
                                     (lisp (lisp (lisp (lisp lisp))))))
                                   (((lisp (lisp (lisp (lisp lisp))))
                                     ((lisp (lisp (lisp lisp)))
                                      ((lisp (lisp (lisp (lisp lisp))))
                                       (lisp lisp))))
                                    (lisp (lisp (lisp lisp))))))))
                               (((lisp (lisp (lisp (lisp lisp))))
                                 ((lisp (lisp (lisp lisp)))
                                  ((lisp (lisp (lisp (lisp lisp))))
                                   ((lisp (lisp (lisp lisp)))
                                    (lisp (lisp (lisp lisp)))))))
                                (((lisp (lisp (lisp (lisp lisp))))
                                  (((lisp (lisp (lisp (lisp lisp))))
                                    ((lisp (lisp (lisp lisp)))
                                     (lisp (lisp (lisp (lisp lisp))))))
                                   (((lisp (lisp (lisp (lisp lisp))))
                                     ((lisp (lisp (lisp lisp)))
                                      (lisp (lisp (lisp lisp)))))
                                    (((lisp (lisp (lisp (lisp lisp))))
                                      (lisp lisp))
                                     (lisp lisp)))))
                                 ((lisp (lisp (lisp lisp)))
                                  ((lisp (lisp (lisp (lisp lisp))))
                                   (((lisp (lisp (lisp (lisp lisp))))
                                     ((lisp (lisp (lisp lisp)))
                                      (lisp (lisp (lisp (lisp lisp))))))
                                    (lisp (lisp (lisp lisp))))))))))
                             ((lisp (lisp (lisp lisp))) (lisp lisp))))))))))))
                   (lisp (lisp (lisp lisp))))))))))))
          (lisp lisp))))
       (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
        ((lisp (lisp (lisp lisp)))
         (lisp (lisp (lisp lisp))))))))))
  (((lisp (lisp (lisp (lisp lisp))))
    (((lisp (lisp (lisp (lisp lisp))))
      ((lisp (lisp (lisp lisp)))
       (lisp (lisp (lisp (lisp lisp))))))
     (((lisp (lisp (lisp (lisp lisp))))
       ((lisp (lisp (lisp lisp)))
        (lisp (lisp (lisp lisp)))))
      (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
       (lisp lisp)))))
   ((lisp (lisp (lisp lisp)))
    (((lisp (lisp (lisp (lisp lisp)))) (lisp lisp))
     ((lisp (lisp (lisp lisp)))
      ((lisp (lisp (lisp lisp))) (lisp lisp))))))))

SYZYGY-DEV 333

Posted 2011-01-27T21:11:06.677

Reputation: 71

Is this an actual language with an implementation? If so, can you please link to it? – Jo King – 2019-04-07T08:04:13.650

@JoKing Wikipedia TIO

– Benjamin Urquhart – 2019-04-07T17:39:12.293

@BenjaminUrquhart Yes, Lisp is a language. Lisplisp however, I have found no evidence exists – Jo King – 2019-04-07T21:33:27.900

@JoKing oh I see. Maybe he was referring to this?

– Benjamin Urquhart – 2019-04-07T22:23:11.620

@BenjaminUrquhart No, that's just another Lisp interpreter – Jo King – 2019-04-07T22:34:50.670

1

Here's a translator to LazyK (Itself simply an implementation of the SKI Combinator Calculus). https://gist.github.com/SYZYGY-DEV333/d74ca36b9a4c504b25c0a2380203c98d

– SYZYGY-DEV 333 – 2019-04-07T22:48:10.563

2

CHIQRSX9+, 1

R

You just have to use the right tool for the problem.
CHIQRSX9+ is Turing complete, and it can read and write from standard channels with C.

Johannes Kuhn

Posted 2011-01-27T21:11:06.677

Reputation: 7 122

CHIQRSX9+ is not a programming language by our usual standards. It does not have a clear specification on the X instruction, and because the RNG is not seeded, the output of the X instruction in the Perl implementation is not consistent across runs, therefore not following a consistent transformational model. This should be deleted.

– Mego – 2015-11-14T17:53:30.913

2@Mego It's hardly fair to apply those standards here when they were written a year after this answer. – Doorknob – 2015-11-14T19:32:01.713

@Mego Does it really matter? If you can find an already existing language that can do the job in 1 character, something is wrong with the question. I'm probably the idiot responsible for all that stupid rules. And the Meta-CodeGolf family is still not forbidden by this definition. – Johannes Kuhn – 2015-11-15T07:41:58.810

2MetaGolfScript is forbidden by a different rule – Mego – 2015-11-15T14:48:50.613

The language you use should not be invented just for solving this particular code golf. It's been done, trust us, and the joke is old hat. -- Source – nyuszika7h – 2014-01-02T18:29:03.177

5@nyuszika7h The language was invented before this question was written, so it is valid. – Johannes Kuhn – 2014-01-02T20:25:06.360

1It's still one of the things it was invented for, though. Seems like cheating to me. – nyuszika7h – 2014-01-02T21:11:07.370

7@nyuszika7h And golfscript was invented to win in code-golf challenges. Do you think that is cheating too? – Johannes Kuhn – 2014-01-02T21:12:01.860

The updated interpreter by ChristopherPeart can satisfy all of the above requirements. – Johannes Kuhn – 2019-04-11T05:15:23.637

2

x86-16 Machine Code, IBM PC DOS, 37 bytes

Binary:

00000000: b408 cd21 3c20 7e1a 8bd0 0c20 3c61 7c0e  ...!< ~.... <a|.
00000010: 3c7a 7f0a b60d 3c6e 7c02 f6de 02d6 b402  <z....<n|.......
00000020: cd21 ebdc c3                             .!...

Build and test using xxd -r

Unassembled listing:

        START: 
B4 08       MOV  AH, 8          ; DOS API read char from STDIN (no echo) 
CD 21       INT  21H            ; read char into AL 
3C 20       CMP  AL, ' '        ; is any non-printable control char?
7E 1A       JL   EXIT           ; if so, end 
8B D0       MOV  DX, AX         ; save original char in DL 
0C 20       OR   AL, 'a'-'A'    ; lowercase the char 
3C 61       CMP  AL, 'a'        ; is char less than 'a'? 
7C 0E       JL   WRCHR          ; if so, do not convert 
3C 7A       CMP  AL, 'z'        ; is char greater than 'z'? 
7F 0A       JG   WRCHR          ; if so, do not convert 
B6 0D       MOV  DH, 'n'-'a'    ; add or subtract 13 
3C 6E       CMP  AL, 'n'        ; is char less than 'n'? 
7C 02       JL   ADD13          ; if so, add 13 
F6 DE       NEG  DH             ; otherwise add -13 
        ADD13: 
02 D6       ADD  DL, DH         ; add 13 or -13
        WRCHR: 
B4 02       MOV  AH, 2          ; DOS API write char to STDOUT 
CD 21       INT  21H            ; write char in DL 
EB DC       JMP  START          ; keep looping 
        EXIT: 
C3           RET                ; return to DOS

As a standalone PC DOS executable program. Input is via STDIN, output to STDOUT.

enter image description here

Re-submitting answer to conform to STDIN challenge requirement.

640KB

Posted 2011-01-27T21:11:06.677

Reputation: 7 149

2

Javascript, 177 bytes

This assumes that there are two functions, print and readLine:

f=String.fromCharCode;print(readLine().replace(/[a-z]/g,function(a){return f((a.charCodeAt(0)-84)%25+97);}).replace(/[A-Z]/g,function(a){return f((a.charCodeAt(0)-52)%25+65);}))

user11

Posted 2011-01-27T21:11:06.677

Reputation:

2

JavaScript 1.8, 106

alert(prompt().replace(/\w/g,function(c)String.fromCharCode(c.charCodeAt()+(c.toLowerCase()<'n'?13:-13))))

JavaScript, 115

alert(prompt().replace(/\w/g,function(c){return String.fromCharCode(c.charCodeAt()+(c.toLowerCase()<'n'?13:-13))}))

This solution solves the problem by adding 13 to the character code if the character in question is in the first half of the alphabet, or subtracting 13 if it's in the second half.

Casey Chu

Posted 2011-01-27T21:11:06.677

Reputation: 1 661

You can save 7 characters by replacing +(c.toLowerCase()<'n'?13:-13)) with -13+26*/[a-m]/i.test(c). – Jacob – 2014-06-11T06:15:35.107

2

PHP - 41 Characters

while($r=fgets(STDIN))echo str_rot13($r);

ircmaxell

Posted 2011-01-27T21:11:06.677

Reputation: 897

5-1 for rep-whoring. – Raynos – 2011-02-03T21:39:33.450

2

C, 136 bytes

I have never felt like any of my solutions are good enough to post on here, but made this for fun, and figured that it will be my gateway drug into code golf.

#define z(x) c>=x&&c<x+13
#define q(w) c>=w&&c<w+13
main(c){for(;(c=getchar())>=0;putchar(z('A')||z('a')?c+13:q('M')||q('m')?c-13:c));}

Tormyst

Posted 2011-01-27T21:11:06.677

Reputation: 21

4Welcome to Programming Puzzles and Code Golf Stack Exchange. Great first answer. And just for the record, we all feel that way sometimes, just know that anything that you create is "good enough" somewhere. – GamrCorps – 2016-02-22T18:21:15.213

2Everything here on PPCG is just for fun (or imaginary internet points) -- please, don't feel the work you've done to craft a solution isn't "good enough" – cat – 2016-02-23T23:36:01.523

Thanks for all the support. I think posting something was all I needed to get my head in gear. I am going to try my hand at more of these challenges soon. – Tormyst – 2016-02-24T02:10:49.317

1

C#, 94 bytes

s=>{var r="";foreach(var c in s)r+=(char)(Char.IsLetter(c)?(c|32)<110?c+13:c-13:c);return r;};

Anonymous function which returns the string of characters rotated by 13 places, based on this C answer from Fors. Works for any lower or upper letters while keeping other input the same.

Full program with ungolfed method and test cases:

using System;

namespace ROT13
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string> f =
            s =>
            {
                var r = "";
                foreach (var c in s)
                    r += (char)(Char.IsLetter(c) ? (c | 32) < 110 ? c + 13 : c - 13 : c);
                return r;
            };

            Console.WriteLine(f("TOO MANY SECRETS!"));   // GBB ZNAL FRPERGF!
            Console.WriteLine(f("too many secrets!"));   // gbb znal frpergf!
            Console.WriteLine(f("gbb znal frpergf!"));   // too many secrets!
            Console.WriteLine(f("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,./"));
// NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm1234567890,./
        }
    }
}

adrianmp

Posted 2011-01-27T21:11:06.677

Reputation: 1 592

1

K, 31

{x^(,/{x!(13_x),13#x}'.Q`A`a)x}

tmartin

Posted 2011-01-27T21:11:06.677

Reputation: 3 917

{x^a(,/-13 13#\:a:.Q.A)?x} for 26 bytes – streetster – 2018-01-31T21:31:34.480

1

Tcl, 74 chars

package require [set c tcl::transform::rot];$c 13 stdin;fcopy stdin stdout

Johannes Kuhn

Posted 2011-01-27T21:11:06.677

Reputation: 7 122

1

Befunge-93, 72 67 bytes

Edit: -5 bytes thanks to James Holderness

<,<v!:+*"a"*`"`"\`\"{":\*"G"*`"@"\`\"[":::_@#+1:~
+0|_\"N"%6-55*1+%

Try it online!

Kinda disappointed in the previous Befunge answers, so I wrote one with much less whitespace.

Jo King

Posted 2011-01-27T21:11:06.677

Reputation: 38 234

1

Haskell - 112 characters

r l=drop 13 l++take 13 l
t=['a'..'z']
s=['A'..'Z']
main=interact$map(\x->maybe x id$lookup x$zip(t++s)$r t++r s)

user1011

Posted 2011-01-27T21:11:06.677

Reputation:

1

Powershell, 77 bytes

-join($args|% t*y|%{[char]((("$_"-match'[a-m]')-("$_"-match'[n-z]'))*13+$_)})

Test script:

$f = {

-join($args|% t*y|%{[char]((("$_"-match'[a-m]')-("$_"-match'[n-z]'))*13+$_)})

}

@(

,("Hello!","Uryyb!")
,("HELLO","URYYB")
,("URYYB","HELLO")
,("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz","NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm")
,("Why did the chicken cross the road?
Gb trg gb gur bgure fvqr!",
"Jul qvq gur puvpxra pebff gur ebnq?
To get to the other side!")

) | % {
    $s,$expected = $_
    $result = &$f $s
    "$($result-eq$expected): $result"
}

Output:

True: Uryyb!
True: URYYB
True: HELLO
True: NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm
True: Jul qvq gur puvpxra pebff gur ebnq?
To get to the other side!

mazzy

Posted 2011-01-27T21:11:06.677

Reputation: 4 832

1

Julia 1.0, 69 bytes

(x->(c=Char(x);print(c+isletter(c)*13*(-1)^(x&31>13)))).(read(stdin))

Try it online!

Explanation

Most of the code is an anonymous function that takes an integer codepoint and prints the corresponding ROT-13'd character:

x->(c=Char(x);print(c+isletter(c)*13*(-1)^(x&31>13)))

x->(                                                )  # Anonymous function of x
    c=Char(x);                                         # Cast x to Char and save as c
                    c+                                 # Start with c and add to its codepoint:
                      isletter(c)*                     # If c is not a letter, the rest of this is
                                                       # multiplied by 0
                                  13*(-1)^(       )    # 13, times +/- 1 according to:
                                           x&31>13     # Low 5 bits of x are greater than 13
                                                       # I.e. x > 'M' (if x is uppercase) or x > 'm'
                                                       # (if x is lowercase)
              print(                               )   # Output the resulting character

We then apply this function, vectorized, to the array of (integer) codepoints returned by read(stdin).

DLosc

Posted 2011-01-27T21:11:06.677

Reputation: 21 213

65 bytes – H.PWiz – 2019-01-02T13:19:58.187

1

///, 217 bytes

/|/\/\///a/n|b/o|c/p|d/q|e/r|f/s|g/t|h/u|i/v|j/w|k/x|l/y|m/z|n/a|o/b|p/c|q/d|r/e|s/f|t/g|u/h|v/i|w/j|x/k|y/l|z/m|A/N|B/O|C/P|D/Q|E/R|F/S|G/T|H/U|I/V|J/W|K/X|L/Y|M/Z|N/A|O/B|P/C|Q/D|R/E|S/F|T/G|U/H|V/I|W/J|X/K|Y/L|Z/M/

Because /// have no input, the input is appended to the end of the program. I have seen another answer done so, but forgot where.

Try It Online!

Note that the program is so slow that it takes more than 60s to run and thus will not do the work in the link.

HighlyRadioactive

Posted 2011-01-27T21:11:06.677

Reputation: 1 585

Welcome to the site! Would it be possible for you to edit in a link to an online interpreter, such as Try It Online!, so that other users may verify your answer?

– caird coinheringaahing – 2019-08-23T12:00:29.817

@cairdcoinheringaahing thanks! I will. – HighlyRadioactive – 2019-08-23T12:01:38.213

There is as problem: the program is too slow that it takes more than 60s to run. – HighlyRadioactive – 2019-08-23T12:10:06.053

That's fine, just mention that in your post, along with the link – caird coinheringaahing – 2019-08-23T12:11:16.183

Thanks, edited. – HighlyRadioactive – 2019-08-23T12:13:11.337

This technically doesn't work for inputs containing any of \/|. Though, the handling of \/ seems like a rather universal problem for ///. – negative seven – 2019-08-23T12:26:10.687

@negativeseven Yeah, sure. Yet, there isn't a way I could think of to get rid of the | except givin' up the whole golfing trick which saves a lot of bytes(260 -> 217). – HighlyRadioactive – 2019-08-23T12:29:48.573

2I dunno, are you sure this isn't jist running into an infinite loop somewhere? Surely it can't be that inefficient that it takes more than 60 seconds to run, even on an empty input – Jo King – 2019-08-23T12:53:48.970

@JoKing You're right, the /a/n/ at the start creates the infinite loop /n/n/ later on if the input contains n (and similarly for other characters). – negative seven – 2019-08-23T13:21:18.383

Oops, sorry. I will fix that. – HighlyRadioactive – 2019-08-23T15:30:22.667

1

naz, 176 bytes

2a2x1v6a8m2x2v9a4a2x3v9a5a2x4v5a2x5v9a4a2x6v9a5a2x7v1x1f1r3x1v7e3x5v5g3x2v2g8f0x1x2f3x4v3l8f0x1x3f3x3v4g9a4a8f0x1x4f9s4s8f0x1x5f3x7v6l8f0x1x6f3x6v4g9a4a8f0x1x7f0a0x1x8f1o1f0x1f

The most involved naz solution I've written so far. This program subtracts 13 from every letter in standard input that's greater than M, and adds 13 to every other letter - whether lowercase or uppercase.

It does use a lot of logic to determine what's a letter or not, so I wouldn't be surprised if this could be improved upon.

Works for any input string terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v                     # Set variable 1 equal to 2
6a8m2x2v                   # Set variable 2 equal to 64 ("@")
9a4a2x3v                   # Set variable 3 equal to 77 ("M")
9a5a2x4v                   # Set variable 4 equal to 91 ("[")
5a2x5v                     # Set variable 5 equal to 96 ("`")
9a4a2x6v                   # Set variable 6 equal to 109 ("m")
9a5a2x7v                   # Set variable 7 equal to 123 ("{")
1x1f                       # Function 1
    1r                     # Read a byte of input
      3x1v7e               # Jump to function 7 if it equals variable 1
            3x5v5g         # Jump to function 5 if it's greater than variable 5
                  3x2v2g   # Jump to function 2 if it's greater than variable 2
                        8f # Otherwise, jump to function 8
1x2f                       # Function 2
    3x4v3l                 # Jump to function 3 if the register is less than variable 4
          8f               # Otherwise, jump to function 8
1x3f                       # Function 3
    3x3v4g                 # Jump to function 4 if the register is greater than variable 3
          9a4a             # Otherwise, add 13 to the register,
              8f           # then jump to function 8
1x4f                       # Function 4
    9s4s8f                 # Subtract 13 from the register, then jump to function 8
1x5f                       # Function 5
    3x7v6l                 # Jump to function 6 if the register is less than variable 7
          8f               # Otherwise, jump to function 8
1x6f                       # Function 6
    3x6v4g                 # Jump to function 4 if the register is greater than variable 6
          9a4a             # Otherwise, add 13 to the register,
              8f           # then jump to function 8
1x7f                       # Function 7
    0a                     # Add 0 to the register
1x8f                       # Function 8
    1o1f                   # Output, then jump to function 1
1f                         # Call function 1

sporeball

Posted 2011-01-27T21:11:06.677

Reputation: 461

1

Javascript (165)

a=prompt();y="ABCDEFGHIJKLMNOPQRSTUVWXYZ";b=y[s="substr"](13)+y[s](0,13);y+=y[l="toLowerCase"]();b+=b[l]();o='';for(i=0;a[i];i++)o+=b[y.indexOf(a[i])]||a[i];alert(o)

or (167) as previous Javascript solution, assuming readLine and print:

a=readLine();y="ABCDEFGHIJKLMNOPQRSTUVWXYZ";b=y[s="substr"](13)+y[s](0,13);y+=y[l="toLowerCase"]();b+=b[l]();o='';for(i=0;a[i];i++)o+=b[y.indexOf(a[i])]||a[i];print(o)

Bob Davies

Posted 2011-01-27T21:11:06.677

Reputation: 111

2Since nobody said it in >2 years, welcome to PPCG! – Erik the Outgolfer – 2016-10-06T11:43:27.223

1

JavaScript 135

s=prompt(),o='',i=0
while((c=s.charCodeAt(i++)))c+=c>64&&c<91?c<52?13:-13:c>96&&c<123?c<109?13:-13:0,o+=String.fromCharCode(c)
alert(o)

wolfhammer

Posted 2011-01-27T21:11:06.677

Reputation: 1 219

1

pyg-i - 76 Bytes

P(STDI.read().t({a:a-13 if(77<a<91)or a>109 else a+13 for a in M(ord,STl)}))

Python Equivient:

import sys,string
print(sys.stdin.read().translate({a:a-13 if(77<a<91)or a>109 else a+13 for a in map(ord,string.ascii_letters)}))

Ian D. Scott

Posted 2011-01-27T21:11:06.677

Reputation: 1 841

Invalid because the interpreter is not available. – cat – 2016-02-22T21:29:59.767

@cat Somehow I got the url wrong. It is fixed now. – Ian D. Scott – 2016-02-23T23:24:02.917

1

Python: 60 bytes

lambda s:''.join([chr((ord(c.lower())-84)%26+97)for c in s])

The only thing I don't like is having that .lower() in there. Any suggestions?

edit: I can get rid of the .lower(), and handle capitals better, but it's 94 bytes now:

lambda s:''.join([chr((ord(c)-(52if ord(c)<97else 84))%26+(65if ord(c)<97else 97))for c in s])

Fred Frey

Posted 2011-01-27T21:11:06.677

Reputation: 21

1

Jolf, noncompeting (language postdates challenge)

Jolf, 3 bytes

Try it here!

,Ri
,R  rot13
  i the input

Or, with new implicit input, ,R.

I'm sorry, but I'm not. I implemented this because it appears often in code-breaking puzzles, which I use Jolf a lot for, and recently used in an ARG. \o/

A longer one (try that one here):

ρi"[%]"γpWpud.pWp2pu+t3 iγH
ρi                           regex replace input
  "[%]"                      "[...]" following
        pWpu                 "abc...xyzABC....XYZ"
       γ                     γ = that
            d                functional replace
             .         _iγH  the index on the alphabet that the element is
                p2pu         shift uppercase alphabet
                    +t3      over thirteen
              pW             upper + lower of that

Conor O'Brien

Posted 2011-01-27T21:11:06.677

Reputation: 36 228

0

Mathematica 102

StringReplace[Input[],
Join@@Table[Rule@@FromCharacterCode/@{i+c,Mod[i+13,26]+c},{c,{65,97}},{i,0,25}]]

chyanog

Posted 2011-01-27T21:11:06.677

Reputation: 1 078

0

J, 32 29 bytes

a.{~3&u:+13*2|&.>:'@MZ`mz'&I.

Try it online!

FrownyFrog

Posted 2011-01-27T21:11:06.677

Reputation: 3 112

0

Jelly, 13 bytes

Ø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.

caird coinheringaahing

Posted 2011-01-27T21:11:06.677

Reputation: 13 702

0

Retina, 13 bytes

13+T`zlZL`l_L

Try it online!

The straightforward transliteration that directly applies ROT13 would be 2 bytes longer Try it online!

Explanation

The transliteration stage here is wrapped in a loop stage making it run 13 times (or until the string is not transformed anymore, which can only happen if the input string has no alphabetic characters).

In the transliteration, characters in zlZL are transformed into the characters at the same positions in l_L. Here, z and Z are exactly what they look like, while l and L get converted into the lowercase and uppercase alphabets. The final letters of those alphabets are ignored because they already appear earlier in the string, and _ is just a placeholder to make the uppercase alphabet line up correctly. The result is transforming each letter into the next one (a->b,b->c,...,z->a); doing this 13 times is ROT13.

Leo

Posted 2011-01-27T21:11:06.677

Reputation: 8 482

0

Japt, 28 bytes

c_d)è"%l")?Z|H)<#n?Z+D:Z-D:Z

Try it!

c_d)è"%l")?Z|H)<#n?Z+D:Z-D:Z
c_                                # map input string through a function
  d)è"%l")?                       # regex check if current character is a letter
           Z|H)<#n?               # is it less than the letter n?
                   Z+D:           # if yes, then add 13
                       Z-D:       # otherwise, subtract 13
                           Z      # not a letter, do not transform

dana

Posted 2011-01-27T21:11:06.677

Reputation: 2 541

20 bytes using replace and switching to v2.0a1. There must be a shorter way, though. – Shaggy – 2019-02-27T17:42:33.877

18 bytes – Shaggy – 2019-02-27T17:45:08.807

Nice - I had not tried the beta version yet. Looks like regex may have improved? – dana – 2019-02-27T17:47:41.323

Yeah, but it's bugged to hell at the moment - only single character class work; anything wrapped in / won't. – Shaggy – 2019-02-27T17:50:00.780

17 bytes. – Shaggy – 2019-02-27T17:50:05.120

0

Python 3, 70 bytes

a=input()
for i in a:print(end=i.isalpha()*chr(65+(ord(i)-52)%26)or i)

alexz02

Posted 2011-01-27T21:11:06.677

Reputation: 89

2Your proposed solution does not work with lowercase letters. It's not explicitely specified in the challenge though, so I'm not sure if your answer is valid. – Nathan.Eilisha Shiraini – 2019-02-27T18:17:58.397

0

T-SQL, 80 bytes

The TRANSLATE function was introduced in SQL Server 2017.

Input is taken from the column I of the table T.

SELECT TRANSLATE(I,A+B,B+A)FROM(VALUES('ABCDEFGHIJKLM','NOPQRSTUVWXYZ'))V(A,B),T

SQL Fiddle

Razvan Socol

Posted 2011-01-27T21:11:06.677

Reputation: 341

0

PHP - 27 Bytes

<?=str_rot13(fgets(STDIN));

DrWhat

Posted 2011-01-27T21:11:06.677

Reputation: 41

0

Zsh, 126 112 106 bytes

Shell builtins only. Rotates any letter in A-Za-z, using decimal-ascii conversion.
126bytes 112bytes 106 bytes

r()printf \\$[[##8](13+$1+(##$X-$1)%26)]
for X (${(s::)1}){case $X {[A-Z])r 52;;[a-z])r 84;;*)printf $X;}}

Initial (wrong) solutions: 56bytes 83bytes

roblogic

Posted 2011-01-27T21:11:06.677

Reputation: 554

0

Scala 108

def m(a:Int,z:Int,c:Int)=if(c>=a&&c<z)a+((c-a+13)%26)else c
"Ok?".map(c=>print(m(65,91,m(97,123,c)).toChar))

ungolfed:

def m (a: Int, z:Int, c:Int) = if (c >= a && c <= z) a+((c-a+13)%26) else c
"Ok?".foreach (c => print (m ('A', 'Z', m ('a', 'z', c)).toChar))

result:

Bx?

user unknown

Posted 2011-01-27T21:11:06.677

Reputation: 4 210

0

Haskell (103)

Reused maybe c id $ lookup c from jloy's answer.

main=interact$map(\c->maybe c id$lookup c$[['a'..'z'],['A'..'Z']]>>=zip<*>uncurry(flip(++)).splitAt 13)

Bolo

Posted 2011-01-27T21:11:06.677

Reputation: 101

0

Scala (96 chars)

def r(s:String)=s.map{c⇒val m = if(c<91)65 else 97
if(c.isLetter)
((c+13-m)%26+m).toChar
else c}

gilad hoch

Posted 2011-01-27T21:11:06.677

Reputation: 717