Solve a Date Shift Cipher

2

1

Introduction

In this challenge you will be solving date shift ciphers. Here is a general overview of what a date shift cipher is. To encode a message, you first must make a key. A key in a date shift cipher is any date converted into the form of MMDDYYYY (Adding zeros at the beginning of each part to keep the key 8 long). For example:

Date - January 23, 1785 (01/23/1785)
 Key - 01231785

Date - April 1, 1999 (04/01/1999)
 Key - 04011999

You must then take your message to encode and write it out.

Hello World!

Write the key under it, repeating if it is too short and ignoring spaces, punctionation, etc.:

Hello World!
04011 99904

Then you shift each letter forward in the alphabet by the number of times of the number below it, looping to A if you pass Z:

Hello World!
04011 99904
Hilmp Fxalh!

Your encoded message is Hilmp Fxalh!. To decode, do the opposite. First, line up the day above the above the letters (it does not need to be above, just personal preference):

04011 99904
Hilmp Fxalh!

Now, shift each letter backward in the alphabet by the number of times above it, looping to Z if you pass A:

Hello World!
04011 99904
Hilmp Fxalh!

And now you have decoded the cipher!

Challenge

Your challenge is to write either two programs, functions, one of each, or one that does both jobs. However, both must use the same language. The first program will accept a string and date in the format of MM/DD/YYYY as input via STDIN, program arguments, or function parameters and encode it using this method. The second program will accept a string and date in the format of MM/DD/YYYY as input via STDIN, program arguments, or function parameters and decode it using this method.

Requirements

First Program/Function

  • Allow input of a string and date in the format MM/DD/YYYY using any method listed above.
  • Must encode the string using a date shift cipher style.

Second Program/Function

  • Allow input of a string and date in the format MM/DD/YYYY using any method listed above.
  • Must decode the string using a diagonal date shift style.

Constraints

  • You cannot use any built-in or external functions that accomplish this task.
  • Standard loopholes are not allowed.
  • Both programs/functions must be in the same language.

Scoring

This is code golf, so shortest program in bytes wins. Bonus -10 bytes for creating a single program/function that accomplishes both tasks.

If I need to add more information, leave a comment!

GamrCorps

Posted 2015-02-28T05:55:05.493

Reputation: 7 058

Question was closed 2015-02-28T08:03:39.740

No answers