CSC322课业解析

题意:
用C语言编写一个名为密码机的系统程序,支持代码的加密和解密功能
解析:
Part A: 基础命令
程序能识别下列5条指令 encrypt 基于凯撒密码对用户输入加密 decrypt 基于凯撒密码对用户输入解密 encode 基于ASCII对用户输入编码 decode 基于ASCII对用户输入解码 exit 退出程序
Part B: 凯撒密码:encrypt/decrypt
凯撒密码是一种加密方式,将26个字母的对应关系全体向前或向后偏移n个单位。例如明文是abc,加密规则是向后偏移3个单位,那么密文就是def。
需要注意的是,后置位的字母超出范围后将对应到前置位的字母上。在这个例子中,明文xyz对应的密文是abc。 实现方法:一次给26个字母按增序编码,例如0、1、2……24、25; 明文a 加密公式E(3,a)=E(3,0)=(3+0)%26=3,根据对应关系加密结果是d。 密文a 解密公式D(3,a)=D(3,0)=(0-3)%26=23,根据对应关系解密结果是x。 由于需要处理数字符号等字符,需要把字符集扩充到ASCII,例如"A"是65,"0"是48,“a”是97。
Part C: 编码和解码(奖励分)
把用户输入转换成二进制码,方法是先把它转为ASCII码,把对应的ASCII码再转换为二进制编码。要注意的是最多使用8位编码,如果缺省补0。例如107对应的二进制数是1101011,但是用0补全缺省,改为01101011。
涉及知识点:
ASCII码,C语言编程
更多可加微信讨论
微信号:tiamo-0620

pdf全文
CSC 322 Systems Programming Fall 2019
Lab Assignment L1: Cipher-machine
Due: Monday, September 23
1 Goal
In the first lab, we will develop a system program (called cipher-machine) which can encrypt
or decrypt a code using C language. It must be an errorless program, in which user repeatedly
executes pre-defined commands and quits when he or she wants to exit. For C beginners, this
project will be a good initiator to learn a new programming language. Students who already
know C language will also have a good opportunity to warm up their programming abilities
and get prepared for the rest of labs.
2 Introduction
A. Basic Commands
The system program provides three basic commands shown in Table 1. The program runs
a related function or exits when a user enters a command as seen in Figure 1. Note that
commands need parameters. Misspelled command should be handled as an exception, and
the program must show an error message. Note that program must be in running and shows
the next prompt.
Table 1. Basic Commands
Command Description
encrypt Encrypt user’s input based on Caesar’s cipher. See the section II-B.
decrypt Decrypt user’s input based on Caesar’s cipher. See the section II-B.
encode Encode user’s input to get a binary code based on ASCII code. See the
section II-C. (extra)
decode Decode user’s binary input to get a character code. See the section II-C.
(extra)
exit Exit the program

The program should run on Linux machine at cs.oswego.edu. Once it is compiled and
executed, it draws user to its own computing environment by showing prompt following the
format: your_loginID $. Figure 1 shows how the prompt looks when the logID is jwlee.
When a command is correctly executed, output will be printed out immediately. The logID
will be printed by using printf function.
jwlee@altair~ > cc lab1-jwlee.c -o lab1
jwlee@altair~ > ./lab1
jwlee $ exot
[Error] Please enter the command correctly!
jwlee $ encrypt(“hello”)
ebiil
jwlee $ exit
jwlee@altair~ >
B. Caesar’s Cipher: encrypt/decrypt
Caesar’s cipher is one of cryptography methods, which has a long history, back to Julius
Caesar’s Roman Empire. He used this simple yet efficient method in sending and receiving
private messages with his subordinates and political comrades. The method is based on a
substitution cipher technique in which substitute an alphabet letter to a different alphabet letter
by a certain rule. Look at the list of alphabets in the Figure 2. In this plaintext each
character has a certain positional number, for example “A” has 1, meaning the first character.
In the same manner, “B” has 2, “C” has 3, and so on. To get the ciphertext, all positional
number is shifted right by a proposed number, 3 in the Figure 2. By the shifting rule, “A”
is now in the 4th position, “B” is in the 5th position.

更多可添加微信哦

你可能感兴趣的:(c)