#00082B

Delta Encoding and Decoding

A delta cipher assigns each letter a distinct value from 0 through 25. The default cipher assigns A=0, B=1, ..., Z=25. A custom cipher lists the letters in increasing value order.

To encrypt text, replace each letter with the letter whose value is the difference, modulo 26, between the current letter's value and the preceding letter's value. A letter preceded by a non-letter is treated as though it were preceded by A. Non-letters are copied unchanged. Letter case is preserved, but case does not affect values. Decryption reverses this process.

Input

The input is a sequence of command lines terminated by end of file. No line has more than 10,000 characters. Command words are case-insensitive and are followed by at least one space:

  • ENCRYPT text encrypts everything after the command using the current cipher.
  • DECRYPT text decrypts everything after the command using the current cipher.
  • CIPHER specification selects a cipher. Ignore spaces and punctuation in the specification. It is valid only when it contains exactly 26 letters with no repetition. A bad specification restores the default cipher.

Any line beginning with another command produces Command not understood.

Output

For ENCRYPT and DECRYPT, print RESULT: followed by the transformed text. For a valid cipher, print Good cipher. Using CIPHER., with its 26 letters uppercase. For an invalid cipher, print Bad cipher. Using default.

Example

Input:

ENCRYPT The quick brown fox leaped over the lazy dog.
CIPHER qwertyuiopasdfghjklzxcvbnm
ENCRYPT The quick brown fox leaped over the lazy dog.
DECRYPT Xsf juwgv fuyzb rcd oaomza nguw xsf olpd evu.
ENCRIPT This won't work!

Output:

RESULT:  Tox qeoui bqxir fjj ltwppz ohjn tox lpzz dls.
Good cipher.  Using QWERTYUIOPASDFGHJKLZXCVBNM.
RESULT:  Xsf juwgv fuyzb rcd oaomza nguw xsf olpd evu.
RESULT:  The quick brown fox leaped over the lazy dog.
Command not understood.

Submit solution

Sign in to submit a solution.