This is the encryption challenge. The decryption challenge can be found here.


The challenge is to encrypt a given string, using the rules as specified below. The string will only contain lowercase alphabets, digits, and/or blank spaces.

Equivalent of a Character

Now, firstly you would need to know how to find the "equivalent" of each character.

If the character is a consonant, this is the way of finding it's equivalent:

1) List all the consonants in alphabetical order
    b c d f g h j k l m n p q r s t v w x y z
2) Get the position of the consonant you are finding the equivalent of.
3) The equivalent is the consonant at that position when starting from the end.

eg: 'h' and 't' are equivalents of each other because 'h', 't' are in the 6th position from start and end respectively.

The same procedure is followed to find the equivalent of vowels/digits. You list all the vowels or the digits (starting from 0) in order and find the equivalent.

Given below is the list of the equivalents of all the characters:

b <-> z
c <-> y
d <-> x
f <-> w
g <-> v
h <-> t
j <-> s
k <-> r
l <-> q
m <-> p
n <-> n

a <-> u
e <-> o
i <-> i

0 <-> 9
1 <-> 8
2 <-> 7
3 <-> 6
4 <-> 5

Rules of Encrypting

  1. You start moving from the left and go towards the right.

  2. If the character is a consonant/digit, then its equivalent is taken and if it is a blank space, then a blank space is taken.

  3. If the character is a vowel, you take it's equivalent and start to move in the opposite direction. For example, if you are moving right and encounter a vowel, encrypt that character then skip to the rightmost unencrypted character and begin encrypting in the left direction, and vice versa.

  4. You shouldn't consider a character in the same position twice. The steps should be followed until all the characters in the input are covered.

  5. The total number of characters in the input(including blank spaces) should be equal to the total number of characters in the output.

Please note that the encrypted characters appear in the output in the order in which they were encrypted.

Now let me encrypt a string for you.

String = "tre d1go3t is"
Moving left to right
"t" -> "h"
"r" -> "k"
"e" -> "o"
Vowel encountered. Now moving right to left.
"s" -> "j"
"i" -> "i"
Vowel encountered. Now moving left to right.
" " -> " "
"d" -> "x"
"1" -> "8"
"g" -> "v"
"o" -> "e"
Vowel encountered. Now moving right to left.
" " -> " "
"t" -> "h"
"3" -> "6"

Output -> "hkoji x8ve h6"


"flyspy" -> "wqcjmc"
"hero" -> "toek"
"heroic" -> "toyike"
"ae" -> "uo"
"abe" -> "uoz"
"the space" -> "htoo jmuy"
"a d1g13t" -> "uh68v8x "
"we xi12" -> "fo78i d"
"this is a code" -> "htioj ixej uy "

You may also choose to use uppercase alphabets instead of lowercase.


This is , so the shortest code wins!

  • 1
    \$\begingroup\$ Step 3 is a bit unclear with regards to switching directions. I think you should say something like "If you are moving right and encounter a vowel, encrypt that character then skip to the rightmost unencrypted character and begin encrypting in the left direction." (If that is what you mean). I think you should also specify explicitly that the encrypted characters appear in the output in the order in which they were encrypted. \$\endgroup\$
    – dylnan
    Feb 8, 2018 at 1:11
  • \$\begingroup\$ @dylnan Added that. \$\endgroup\$ Feb 8, 2018 at 1:14
  • 1
    \$\begingroup\$ @AgniusVasiliauskas: One way of doing it would be: Apply the same character transformations. Keep 2 decrypt strings. Loop over the string left-to-right. Alternate between appending chars to the first string and prepending to the second every time you handle a vowel. Merge the strings at the end. \$\endgroup\$
    – Emigna
    Feb 8, 2018 at 10:00
  • 4
    \$\begingroup\$ There will soon be a decryption challenge for the same, in which I will try to explain the process \$\endgroup\$ Feb 8, 2018 at 10:38
  • 1
    \$\begingroup\$ For the curious, in Indian English alphabet means letter. \$\endgroup\$
    – TRiG
    Feb 8, 2018 at 11:22

8 Answers 8


05AB1E, 22 bytes


Try it online! or as a Test suite


v                        # for each char in input
 ć                       # extract the head of the current string (initially input)
  žN‡                   # transform consonants
      žM‡               # transofrm vowels
          žh‡           # transform numbers
              D?         # print a copy of the current char
                žMsåi    # if the current char is a vowel
                     R   # reverse the rest of the string
  • \$\begingroup\$ žhžMžN)UvćXJXíJ‡D?žMsåiR was what I was thinking for improvement, but can't cut XJXiJ down enough. \$\endgroup\$ Feb 8, 2018 at 14:34
  • \$\begingroup\$ @MagicOctopusUrn: I had a similar idea with DJsíJ which wasn't very effective either. \$\endgroup\$
    – Emigna
    Feb 8, 2018 at 15:02

JavaScript (Node.js), 173 ... 166 156 ... 124 123 bytes

-28 byte Thanks Arnauld


Try it online!

In the first iteration the String will be changed to Array, and subsequent iterations will continue to use Array. Voilà!

Original Approach (166 bytes):

  • \$\begingroup\$ & didn't work for some numbers but && worked. Thanks. \$\endgroup\$ Feb 8, 2018 at 7:56
  • \$\begingroup\$ Oh yes, I didn't find a method to optimize that and you did it! Thanks! \$\endgroup\$ Feb 8, 2018 at 8:07
  • 3
    \$\begingroup\$ 124 bytes by using the same string for all letters and applying some more golfing. \$\endgroup\$
    – Arnauld
    Feb 8, 2018 at 9:41
  • \$\begingroup\$ Wow brilliant! I didn't think of combining the strings AT ALL \$\endgroup\$ Feb 8, 2018 at 10:01
  • \$\begingroup\$ q=="0"|+q is actually 1 byte shorter than q>" "&&1/q. \$\endgroup\$
    – Arnauld
    Feb 8, 2018 at 11:31

C, 196 bytes

#define C(k,m)for(i=m;i--;)k[i]-c||putchar(k[m+~i],r^=m==5);
r;p(c,i){C("bcdfghjklmnpqrstvwxyz",21)C("0123456789",10)C("aeiou",5)C(" ",1)}f(S){char*s=S,*t=s+strlen(s);for(r=1;s<t;)p(r?*s++:*--t);}

Try it online!


J, 132 bytes

f=:3 :0
while.*#y do.a=.a,{.y rplc(g c),(g d),g v
y=.|.^:({:a e.v)}.y

Try it online!

A verbose explicit verb this time.


c=.(u:97+i.26) makes a list a-z

v=.'aeiou' makes a list of vowels

-. removes the vowels from the list of letters

d=.u:48+i.10 makes a list of digits

g=.;"0|. a utility verb for creating a list of boxed pairs of replacement symbols

   g d

a=.'' a list to store the result

while.*#y do.a=.a,{.y rplc(g c),(g d),g v while the length of the list is > 0 take a symbol, replace it and append it to the result

y=.|.^:({:a e.v)}.y drop one symbol from the beginning of the list and if the symbol is a vowel, reverse the list

end. ends the while loop

a returns the result


Clean, 221 206 198 190 186 178 bytes

import StdEnv
|s>[]=[j\\e<-a++b%(0,0),i<-['in ':l]&j<-['in ':r l]|e==i]++ $(init(r b))=s

Try it online!


Stax, 24 bytes

╥j•td╢Ä;Sµ*ûⁿvÉ╫î▓J o╩π╗

Run it

Here is the ascii representation of the same program.


It translates each character class first, then begins a while loop. In the loop, it outputs the next character, and conditionally reverses the rest of the string if a vowel is encountered.

VcG                             Push lowercase consonants and jump to trailing }
   VdG                          Push digits and jump to trailing }
      VvG                       Push lowercase vowels and jump to trailing }
         wB]qVvs#!Hv*c          While; run this block until popped value is falsy
          B]                    Split first character off string 
            q                   Output with no newline; keep on the stack
             Vvs#               1 if letter is a vowel, 0 otherwise
                 !Hv            Not, Double, then Decrement
                                    -1 for vowels, 1 otherwise
                    *           Multiply string. -1 causes reversal       
                     c          Copy value to be popped as while condition
                      }         Jump target from above.  Return when done.
                       cr\$     Copy, reverse, zip, and flatten.
                           |t   Translate: use string as a character map
                                    for replacements

Brachylog, 43 39 bytes


Try it online!

I only bothered finishing this grand mess because I'm struggling to make Jelly cooperate...


Retina, 78 69 bytes



Try it online! Link includes test cases. Explanation:


Swap each character with its equivalent. The Ro causes the string to transliterate to its reverse. The middle consonant n and vowel i map to themselves so don't need to be listed. The first 10 consonants are listed first and the last 10 last so that they transliterate to each other. The first and last two vowels then surround the digits. (The o is normally special so it has to be quoted here.)


Repeat while a vowel remains.


Output the text up to the vowel.


Delete the text up to the vowel.


Reverse the remaining text. When there are no vowels left, this is then implicitly output, however for the purposes of the test cases, the header outputs the text at the end of each line.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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