Reference no: EM133271846
Practical work
For this second practical work of the session, we ask you to implement a transposition cipher system: the Myszkowski transpose.
To work, the latter takes a key and text as input, as well as a mode to decide whether to encrypt or decrypt the text entered.
For explanations of the principle and to test on a valid implementation
Specifications
The program will successively ask for the key to use, then the text to be processed, and finally the mode (encrypt or decrypt), before calculating the output text.
The key is a text with a minimum length of 1 character, and a maximum of 8 characters. We don't put any constraints on the text, except that the \x00s won't be in the input.
The text is also a text with a minimum length of 1 character, and a maximum of 150 characters. Here, two constraints:
- Encryption: no \x00, nor =.
- Decryption: no \x00.
Finally the operation mode will be either e to encrypt, and d to decrypt. Note that each entry is on a separate line.
We provide you with the character strings to add in your program, you will have to use them as they are, and display them when it is relevant. The tests will verify that they are exactly equal to what we provide, and we will apply penalties if there is any discrepancy.
Key processing
The Myszkowski cipher relies on a first pass over the key to assign a number to each unique character of the entered key. The order we use to determine how to assign these digits is the lexicographical order. To simplify, we will consider the ASCII codes of each character as their value.
For instance:
A (0x41) < B (0x42) < C (0x43) < a (0x61) < b (0x62) < c (0x63)
Therefore, each unique character in the key will need to be affixed with the correct number in that order.
Examples of keys and numbering:
ABCA -> 1231
CBAB -> 3212
ACBC -> 1323
This numbering method will be used to encrypt and decrypt input texts.
encryption
For encryption to work, you will need to align your key and your input. To do this, add as many = characters as necessary to the end of the input so that the lengths of the key and your input text are equal, modulo the size of the key.
To put this in code: len(text) len(key) == 0. Example:
Key: ABCD (length 4)
Text: sample_text (length 13)
Padded text: sample_text=== (length 16)
To encrypt an input via this method, you will first have to process the key as mentioned in the previous point, then apply this key in a loop over all the characters of the text to be encrypted. For each character, if the current position is equal to the corresponding one in the key, modulo the size of the key, and if the current iteration is the one corresponding to the number assigned to the character matching in the key, you can write that character as the next character in the output.
Here is the pseudocode corresponding to this description:
var output string // encrypted text to be calculated var text string // input text, padded
var cleNum []int // numbers assigned to each character of the key
iteration = 1
outputPosition = 0
while true {
found = false positionText = 0
KeyPosition = 0
while positionText < len(text) {
if keyNum[keyPosition] == iteration { output[outputPos] = text[textPosition] found = true
}
KeyPosition++
if keyPosition >= len(keyNum) { keyPosition = 0
}
positionText++
}
if !found {
break
}
iteration++
}
Decryption
The encryption corollary uses a method similar to encryption, you will need to number the characters of your key. The text entered will not need to be padded, it will have to respect the constraint of len(text) len(key) == 0. To simplify the realization, you can assume that it is valid (we will not test malformed entries).
Once the decryption is functional, you will have an output possibly padded with =. Before displaying the decrypted text to the user, you will need to unalign it: remove all = characters from the output at the end of the string.
Here is the decryption pseudo-code:
var output string // decrypted text to be calculated var text string // encrypted text entered
var cleNum []int // numbers assigned to each character of the key
iteration = 1
inputPosition = 0
while true {
found = false outputPosition = 0
KeyPosition = 0
while outputPosition < len(text) {
if keyNum[keyPosition] == iteration { output[outputPosition] = text[inputPosition] inputPosition++
}
KeyPosition++
if keyPosition >= len(keyNum) { keyPosition = 0
}
outputPosition++
}
if !found {
break
}
iteration++
}
Evaluation
This practical work counts for 15% of the final grade of the course.
In detail, here are the evaluation criteria that we will take into account:
Program operation
We deliver tests to you with this TP, you will have to pass all the tests we deliver to you, as well as private tests. Markers will also be able to add tests that must be passed to obtain the maximum score.
To run the tests, use the "input" file as input (Batch I/O) in the simulator, and compare the output to the corresponding "output" file. Note that if there are differences in the case of the messages or differences (punctuation, emphasis, etc.), the test will not count as completely failed, but a penalty of up to 50% will be applied to the score for the test.
NOTE: Your program MUST be called myszkowski.pep. If the name does not correspond to this instruction, a global penalty of 15 points will be imposed.
Naming
To carry out the realization of the program, you will probably need to declare labels. As far as possible, and knowing the limits of PEP/8 (8 characters maximum for each), you should name them clearly. This facet will also be taken into account in the rating of your achievement.
Comments
Given that it is assembler, and that the programs are essentially rather obscure, we ask you to comment adequately on your achievements, so that everything is clearer on proofreading. Note that comments should explain your work, not paraphrase your code.
Code quality
Even if it is assembler, we will assess the quality of the code you submit. We will sanction any unnecessary complexity, make sure that the code you render is as clear and concise as possible, without hindering the reading.
Suggestion
Given that the subject is considerably more complex than lab1, we do not recommend that you do the lab directly in assembler. To cement the algorithm to be written, we suggest that you write a first implementation in a higher level language (Java, C, Python, etc.), applying constraints: do not use library functions that you will not be able to use in Assembler directly (for example Maps, Sets, etc.). You will eventually be able to use reading primitives that come with these languages, but keep in mind that you will have to reimplement them in assembler to replicate the operation of the lab.
Attachment:- Cipher system.rar