Write a complete program that will correctly decode a set of characters into a valid message. Your program should read a given file of a simple coded set of characters and print the exact message that the characters contain. The code key for this simple coding is a one for one character substitution based upon asingle arithmetic manipulation of the printable portion of the ASCII character set.
Input and Output
For example: with the input file that contains:
1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5
your program should print the message:
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
Your program should accept all sets of characters that use the same encoding scheme and should print the actual message of each set of characters.
Sample Input
1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5
Sample Output
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
-----------------------------------------------------------------------------------------------
解密的方法是输入的字符需要转换成为ASCII码后,减去7,即可得到所需要的字符
程序如下:
02
03 #define DECODER 7
04
05 int main()
06 {
07 char c = 0;
08
09 while (( c = getchar()) != EOF)
10 {
11 if ( c != '\n')
12 {
13 putchar( c - DECODER);
14 }
15 else
16 {
17 putchar( c);
18 }
19 }
20
21 return 0;
22 }
本文介绍了一种简单的ASCII码字符替换解密方案,通过将特定编码的字符减去7来还原原始消息。提供了C语言实现的例子,展示了如何读取编码文件并打印解码后的消息。
6477

被折叠的 条评论
为什么被折叠?



