Given a string of text that contains lowercase letters, encode it as follows: (I will be using abcdef)

  • First, encode the alphabet cipher, but this time, 0-indexed. 000102030405
  • Reverse it. 504030201000
  • Loop through the string.
    • If the next two digits together are 25 or smaller, encode those two numbers. 5 04 03 02 01 00 0
    • Otherwise, encode one number. f e d c b a a
  • Join. fedcbaa

Test cases

abcdef                          fedcbaa
abcdefghijklmnopqrstuvwxyz      fyxwvucjsrqponmlktihgfedcbaa
helloworld                      dbromylloha
ppcg                            gcfpb
codegolf                        fboqedema
programmingpuzzlesandcodegolf   fboqedemddkiobpzuzqdscmkhqerpb

Encoder (not golfed)

Remember, this is , so the code with the fewest bytes wins.

  • 1
    \$\begingroup\$ I get different answers for some of the test cases. For example, codegolf becomes 0214030406141105, reversing to 5011416040304120, split as 5,01,14,16,04,03,04,12,0 turning into fboqedema instead of fbobgedema as you have. \$\endgroup\$ Nov 6, 2016 at 23:50
  • \$\begingroup\$ @GabrielBenamy Fixed. Thank you for telling me. \$\endgroup\$
    – Oliver Ni
    Nov 7, 2016 at 1:39
  • \$\begingroup\$ @xigoi cc actually encodes to uu. \$\endgroup\$
    – Oliver Ni
    Jul 12, 2021 at 16:10
  • \$\begingroup\$ @OliverNi Sorry, I forgot about the leading zeros. An actual example of why this isn't reversible is that both qx and qcd encode to dcgb. \$\endgroup\$
    – xigoi
    Jul 12, 2021 at 17:48
  • \$\begingroup\$ @xigoi Ah yep, you're right. Not a great challenge tbh, but i wrote it a long time ago so \$\endgroup\$
    – Oliver Ni
    Jul 13, 2021 at 1:33

4 Answers 4


JavaScript, 126 125 bytes


Try it online!


Perl, 73 + 2 = 75 bytes

Run with the -lp flag


Haskell, 107 bytes

g(a:b:c)|r<-read[a,b],r<26=['a'..]!!r:g c
g(a:b)=[a..]!!49:g b
g e=e

Try it online!


05AB1E, 31 26 bytes

-5 bytes after taking a look at Lynn's Haskell answer.


Try it online!

Ç                     # codepoints of the input
 3+                   # add 3 to each (a->100, b->101, ...)
   €¦                 # remove the leading "1" from each number/string 
     J                # join into a single string
      R               # and reverse the string
[                     # infinite loop
 Ð                    # push 2 copies of the current remaining string s   s, s, s
  2£                  # take the first two chars of s                     s[:2], s, s
    ₂‹                # are they (as a number) less than 26 (0 or 1)      s[:2]<26, s, s
      >D              # add 1 and duplicate the result                    (s[:2]<26)+1, (s[:2]<26)+1, s, s
        Š             # rotate the top three items on the stack           (s[:2]<26)+1, s, (s[:2]<26)+1, s
         £            # take the first or two first characters from s     s[:(s[:2]<26)+1], (s[:2]<26)+1, s
          Aè          # index with those into the alphabet                
            ?         # and print the result without a trailing newline
             .$       # remove the characters from s                      s[(s[:2]<26)+1:]
               DõQ#   # if s is now empty, exit the loop

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.