A delta cipher is a very simple encryption scheme that is a big improvement over a substitution cipher. Each of the 26 letters A–Z is assigned a numeric value from 0 to 25. The assignment is one-to-one (a permutation of the letters), but not necessarily in alphabetical order. The default cipher assigns A = 0, B = 1, …, Z = 25, and is used until a valid new cipher is supplied.
Encryption is based on the differences between the values of successive letters.
A.A and a denote the same letter and therefore share the same value.Decryption reverses the process, reconstructing the original text one letter at a time.
The input is a sequence of commands, one per line, terminated by end of file. No line contains more than 10000 characters. There are three commands, and the case of the letters in a command word does not matter. Each command word is followed by at least one space.
ENCRYPT — the rest of the line is plain text to encrypt with the current cipher.DECRYPT — the rest of the line is encrypted text to convert back to plain text with the current cipher.CIPHER — the rest of the line defines a new cipher. It must contain exactly twenty-six letters with no repetitions; spaces and punctuation are ignored. Their order fixes the values: the first letter has value 0, the second has value 1, and so on.Any line whose first word is none of these three commands is not understood.
Produce one line of output for each input line. The spacing shown below is part of the required output and must be reproduced exactly; in particular, every output line ends with a single trailing space.
ENCRYPT and DECRYPT: the text RESULT: then two spaces, then the transformed text, then one trailing space.CIPHER: the text Good cipher. then two spaces, then Using, a space, the twenty-six letters in uppercase, then a period and one trailing space. The new cipher is used for all following commands.CIPHER (wrong number of letters or a repeated letter): the text Bad cipher. then two spaces, then Using default. and one trailing space; the default cipher is used from then on.Command not understood. followed by one trailing space.