I have loads of different ciphers stored in a document I once compiled as a kid, I picked a few of the ones I thought were best suitable for challenges (not too trivial, and not too hard) and transformed them into challenges. Most of them are still in the sandbox, and I'm not sure yet whether I'll post all of them, or only a few. Here is the third and easiest one (after the Computer Cipher and Trifid Cipher I posted earlier).
With a Clock Cipher we use the following image to encipher text:
t h i s i s a c l o c k c i p h e r (without additional spaces of course, but added as clarification) 19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17
Given a string
sentence_to_encipher, encipher it as described above.
- You can assume the
sentence_to_encipherwill only contain letters and spaces.
- You can use either full lowercase or full uppercase (please state which one you've used in your answer).
- You are not allowed to add leading zeros for the single-digit enciphered letters
j, but two zeros
00are mandatory for spaces.
- You should use
:as separator, and an additional leading or trailing
:is not allowed.
- You are allowed to use lowercase
pminstead of uppercase
PM, as long as it's consistent.
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Input: "this is a clock cipher" Output: "19:7:8:18:00:8:18:00:AM:00:2:11:14:2:10:00:2:8:15:7:4:17" Input: "test" Output: "19:4:18:19" Input: "what time is it" Output: "22:7:AM:19:00:19:8:12:4:00:8:18:00:8:19" Input: "acegikmoqsuwy bdfhjlnprtvxz" Output: "AM:2:4:6:8:10:12:14:16:18:20:22:24:00:1:3:5:7:9:11:13:15:17:19:21:23:PM" Input: "easy peazy" Output: "4:AM:18:24:00:15:4:AM:PM:24"