#T580. 密码破译
密码破译
Description
Julius Caesar lived in an era fraught with danger and intrigue, where survival was the greatest challenge. To secure military communications, he devised one of the earliest cryptographic systems.
Assume you are an officer in Caesar's legion tasked with decrypting his messages and relaying them to your general. The encryption method works as follows: each letter in the original message is replaced by the letter five positions later in the alphabet (e.g., every letter A in the original message is replaced by F). Your mission is to reverse this process and recover the original message.
Encrypted letters: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Original letters: V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
Note: Only letters are substituted; non-alphabetic characters remain unchanged. All letters in the original message are uppercase.
Input Format
The input consists of no more than 100 datasets. There are no blank lines between datasets. Each dataset comprises three parts:
- Start line:
START - Encrypted message: A single line containing 1 to 200 characters, representing an encrypted message from Caesar.
- End line:
END
After the last dataset, there is an additional line: ENDOFINPUT
Output Format
For each dataset, output a single line containing the decrypted original message.
START
NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
Hint
Note: The test data includes multiple messages, so pay attention to the input method.
The gets function has caused a large number of buffer overflow vulnerabilities in history because it cannot limit the input length. Therefore, it has been completely removed in the latest versions. Please use the fgets function as a replacement. Alternatively, you can use the following macro definition to replace it:
#define gets(S) fgets(S,sizeof(S),stdin)
Source
CodesOnline