11
\$\begingroup\$

Write some code in any language that inputs a string such as "Today is a great day" (Note that there is no punctuation) and converts it to the "Secret Language". Here are the rules for the "Secret Language".

  • a=c, b=d, c=e and so on (y=a and z=b)
  • separate each word by a space
  • make sure there is proper capitalization

Example:

Input: "Today is a great day"

Output: "Vqfca ku c itgcv fca"

It is a popularity-contest. Other users should give points by looking for most "to the point" yet "unique" code.

CHALLENGE: I was looking up uncommon programming languages and I found a language called Piet (esolang). I challenge anyone to write it in this language.

\$\endgroup\$
7
  • \$\begingroup\$ Shouldn't that be x=z, y=a, z=b? \$\endgroup\$
    – r3mainer
    Commented Feb 16, 2014 at 0:46
  • \$\begingroup\$ you are right "duh" :) \$\endgroup\$
    – Vik P
    Commented Feb 16, 2014 at 0:47
  • 3
    \$\begingroup\$ I was confused until I realized a=c is a -> c. \$\endgroup\$
    – Justin
    Commented Feb 16, 2014 at 4:10
  • 6
    \$\begingroup\$ In other words, ROT2 it \$\endgroup\$ Commented Feb 16, 2014 at 8:39
  • 3
    \$\begingroup\$ Both rot13 and rot2 are both Caesar ciphers with different keys (13 and 2). \$\endgroup\$
    – Sylwester
    Commented Feb 16, 2014 at 15:42

35 Answers 35

1
2
0
\$\begingroup\$

C#, 163

Yes, this is not code-golf. I went for shortest anyway (or at least, made a first stab at it)

using System.Linq;class P{static void Main(string[]a){System.Console.WriteLine(string.Concat(a[0].Select(c=>(char)(c==32?c:c<89?c+2:c<91?c-24:c<121?c+2:c-24))));}}

Formatted:

using System.Linq;
class P
{
    static void Main(string[] a)
    {
        System.Console.WriteLine(string.Concat(a[0].Select(c => (char)(c == 32 ? c : c < 89 ? c + 2 : c < 91 ? c - 24 : c < 121 ? c + 2 : c - 24))));
    }
}

Yes, I did have a peek at ufis' answer.

\$\endgroup\$
0
\$\begingroup\$

C# 5KB

(381 chars)

391

using System;
namespace WinHelper {
    class P {
        static void Main(string[] args) {
            char[] f =  "abcdefghijklmnopqrstuvwxyz ".ToCharArray();
            char[] g =  "cdefghijklmnopqrstuvwxyzab ".ToCharArray();

            foreach (char c in Console.ReadLine().ToCharArray().ToLower()) 
                Console.Write(g[Array.FindIndex(f, a => a == c)]);
        }
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Compiled size (5KB) doesn't matter. For code-golf the number of chars (of sourcecode) usually counts, but since this particular challenge is a popularity contest and not code-golf the chars/size doesn't matter at all. Hover your mouse over the popularity contest badge beneath the challenge (you'll see a tooltip explaining it: "A popularity-contest is a competition where the correct answer with the most upvotes wins, usually the most creative answer"). \$\endgroup\$
    – RobIII
    Commented Feb 20, 2014 at 15:13
  • \$\begingroup\$ Also, it crashes on the challenge's example input Today is a great day since it doesn't support uppercase letters. \$\endgroup\$
    – RobIII
    Commented Feb 21, 2014 at 1:24
0
\$\begingroup\$

Bash, 8 characters

...if you happen to have the bsdgames package installed! Reads from standard input.

caesar 2

Example

echo Today is a great day|caesar 2

Output: Vqfca ku c itgcv fca

\$\endgroup\$
0
\$\begingroup\$

C

#include <stdio.h>
char c[100];
int main()
{
gets(c);
char *p=c,x;
while(*p)
{
    x=*p;
    if(x>='a'&&x<='z')
    {
        *p=((*p-'a'+2)%(26)+'a');
    }
    if(x>='A'&&x<='Z')
    {
        *p=((*p-'A'+2)%(26)+'A');
    }

    p++;
}
puts(c);
}
\$\endgroup\$
-1
\$\begingroup\$

Brainfuck

Must have (at least) 7-bit wrapping cells to work.

+[>,>+++++[<------>-]>[<<++++++++++++++++++++++++++++++.>>>+<]>-[<<<++++++++++++++++++++++++++++++++.[-]]<]
  • Infinite input loop +[
  • Get input >,
  • Make a loop to get number 30 >+++++[<------>-]>
  • If the symbol is a space, output the space [<<++++++++++++++++++++++++++++++.>>>+<]>-
  • Otherwise, shift the ASCII value by two and output [<<<++++++++++++++++++++++++++++++++.[-]]<
  • Get more input ]
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Timtech, you really like posting esoteric solutions without explaining what they do. When posting your answers, don't forget the explanation. \$\endgroup\$
    – Justin
    Commented Feb 17, 2014 at 0:58
  • \$\begingroup\$ -30 will always be true so it will just output the first character as is infinitely. \$\endgroup\$
    – Sylwester
    Commented Feb 17, 2014 at 10:18
  • \$\begingroup\$ @Quincunx Explanation added. \$\endgroup\$
    – Timtech
    Commented Feb 17, 2014 at 14:08
  • 1
    \$\begingroup\$ @Timtech Very unusual cell size and I read at least as it would have to be a minimum. Where do you get a 7 bit interpreter? \$\endgroup\$
    – Sylwester
    Commented Feb 18, 2014 at 17:19
  • 1
    \$\begingroup\$ @Timtech 8 bit wrapping I can do and my interpreter is still printing Vqfc{"ku"c"itgcv"fc{ instead of Vqfca ku c itgcv fca. \$\endgroup\$
    – Sylwester
    Commented Feb 19, 2014 at 1:24
1
2

Not the answer you're looking for? Browse other questions tagged or ask your own question.