28
\$\begingroup\$

Given a string that contains only lowercase letters, encode that string with the alphabet cipher.

To encode with the alphabet cipher (I will be using the example hello):

  1. First, convert each letter in the string to a number depending on its position in the alphabet (a = 1, b = 2, etc.) Example: 8 5 12 12 15
  2. Pad each number to two characters with 0s. Example: 08 05 12 12 15
  3. Join. Example: 0805121215

Test cases

helloworld -> 08051212152315181204
codegolf -> 0315040507151206
alphabetcipher -> 0112160801020520030916080518
johncena -> 1015081403051401

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

\$\endgroup\$
1

64 Answers 64

1 2
3
0
\$\begingroup\$

brev, 57 bytes

(over(display(pop(number->string(+(char->integer x)4)))))

Everyone came up with the +4 🤷🏻‍♀️

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

GolfSharp, 37 bytes

s=>s.s(n=>(n<106?"0":"")+(n-96)).j();
\$\endgroup\$
0
\$\begingroup\$

CJam, 9 bytes

{i4+s1>}%

Try it online!

A function taking a string as input. Port of many other answers.

Explanation

{      }% # for each value in the input
 i        # convert it into a number
  4+      # add 4 to it
    s     # convert it to a string
     1>   # drop the first character

A version which isn't a port, for fun:

CJam, 11 bytes

{'`-sYTe[}%

Try it online!

Explanation

{        }% # map the following across the input
 '`-        # subtract the codepoint of '`', 96, from each value
    s       # convert to a string
       e[   # and pad the left with
      T     # 0s to length
     Y      # 2
\$\endgroup\$
0
\$\begingroup\$

Thunno 2 JB, 5 bytes

4+ıṘḣ

Attempt This Online!

Port of Adnan's 05AB1E answer.

Explanation

4+ıṘḣ  # Implicit input
       # Convert to codepoints
4+     # Add four
  ı    # Map:
   Ṙ   #  Convert to string
    ḣ  #  Remove the first item
       # Join the list
       # Implicit output
\$\endgroup\$
1 2
3

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.