304 North Cardinal St.
Dorchester Center, MA 02124

# Symmetric Cryptography Peer-graded Assignments Solution

## Get All Symmetric Cryptography Peer-graded Assignments Solution

Symmetric cryptography relies on shared secret key to ensure message confidentiality, so that the unauthorized attackers cannot retrieve the message. The course describes substitution and transposition techniques, which were the bases for classical cryptography when the message is encoded in natural language such as English.

Then, we build on product ciphers (using both substitution and transposition/permutation) to describe modern block ciphers and review the widely used cipher algorithms in DES, 3-DES, and AES. Lastly, we enable the use of block ciphers to support variable data length by introducing different modes of block cipher operations in ECB, CBC, CFB, OFB, and CTR modes.

Enroll on Coursera

#### Honors Peer-graded Assignment: Pseudo-Code: Vigenere Cipher Solution

This assignment is to build a pseudo-code for the Vigenere Cipher which takes English letters (26 alphabets) as inputs and outputs. Define the variables and use a pseudo-code to describe the encryption using Vigenere Cipher. The pseudo-code should support a key of arbitrary length, e.g., by having the key as an input variable.

Define all the variables that you use and clearly document the variables and each steps/lines of your pseudo-code, and be as brief as possible. Your assignment will be graded based on the correctness (does it work, e.g., did you miss any steps?) and presentations (e.g., is it easy to follow the variable definitions, logic, and the steps? Is the pseudo-code unnecessarily long?). As for presentation, you would want enough details/documentation, so that a person with introductory programming background (with any language) but no prior knowledge about Vigenere Cipher to be able to understand your logic.

#### Honors Peer-graded Assignment: Pseudo-Code: Vigenere Cipher Solution

##### Which programming language, if any, are you familiar with?

I am familiar with Java and Python.

We take the plaintext as p and ciphertext as c which we produce from plaintext during encryption and we produce the plaintext back from the ciphertext using the decryption steps. We encrypt the plaintext p of arbitrary length using key stream generated from key k of arbitrary length.

such that c_i = (p_i + k_i) mod 26 where k_i = key_{i mod m} where m is the length of the key. The pseudo-code is represented as:

``````m <-- length of key
for index, character in plaintext:
ciphertext[index] <-- (character + key[index % m]) % 26

return ciphertext
``````

This encryption algorithm can be represented in Python as

```def encrypt(plaintext: str, key: str) -> str:
ciphertext = ''
m = len(key)
for i, letter in enumerate(plaintext.lower()):
ciphertext += chr((char_2_num(letter) + char_2_num(key[i % m])) % 26 + ord('a'))
return ciphertext.upper()

def char_2_num(character: str) -> int:
return ord(character.lower()) - ord('a')```

where `char_2_num` is a utility function. Similarly we decrypt the ciphertext using the key by the following pseudo-code:

``````m = length of key
for index, character in ciphertext:
plaintext[i] <-- (character - key[index % m]) % 26

return plaintext
``````

The algorithm in Python is represented as:

```def decrypt(ciphertext: str, key: str) -> str:
plaintext = ''
m = len(key)
for index, letter in enumerate(ciphertext.lower()):
plaintext += chr(
(char_2_num(letter) - char_2_num(key[index % m])) % 26 + ord('a'))
return plaintext.lower()```

#### Peer-graded Assignment: DES Overview Pseudo-Code Solution

Use a pseudo-code to describe the DES encryption which takes 64-bit input/output. Define the subkeys for all rounds (a total of 768 bits) as input variables. You are given the following functions/blocks (you can just use these without implementing how they work, but define the other functions if you use others):

— IP (the initial permutation, taking 64 bits of input and outputting 64 bits)

— F (the round function, taking 32 bits of data and 48 bits of subkey and outputting 32 bits)

— FP (the final permutation, taking 64 bits of input and outputting 64 bits)

Define all the variables that you use and clearly document the variables and each steps/lines of your pseudo-code, and be as brief and clear as possible. Your assignment will be graded based on the correctness (does it work, e.g., did you miss any steps?) and presentations (e.g., is it easy to follow the variable definitions, logic, and the steps? Is the pseudo-code unnecessarily long?).

As for presentation, you would want enough details/documentation, so that a person with introductory programming background (with any language) but no prior knowledge about DES to be able to understand your logic.

#### Peer-graded Assignment: DES Overview Pseudo-Code Solution

##### Which programming language, if any, are you familiar with?

I am familiar with Java and Python.

Permutation Box (PBOX)

The DES Algorithm requires many smaller structures such as the Substitution Box, Permutation Box, The Mixer and Swapper which Compose a Single Round of Feistel Cipher etc. We describe all structures below:

``````PBox:
key = [5 4 78 45 .... 64] // an n length key for permuting a given sequence

function permute(sequence):
result <-- new sequence
for index, element in sequence:
result[key[index]] = element
endfor
return result
endfunction
``````

Substitution Box (SBox)

In the substitution box we will have a table that will provide us with mappings from 2 dimensional bit tuples to a 4-bit binary sequence and we obtain the 2 dimensional tuple from a given binary sequence.

We compose our `SBox` with a `func` which is a function which returns `(row, column)` tuple from binary input.

``````SBox:
table <-- provided by user
func <-- function for getting (row, column) from binary input

function substitute(binary)
row, column = func(binary)
return table[row][column]
endfunction
``````

Swapper

Swapper is a simple Cipher part of a single round of the DES Cipher except the last round. The last round in the DES cipher contains no swapper component. The swapper imply takes in a binary sequence and splits it into 2 and then swaps both components to return a new binary sequence.

``````Swapper:
function encrypt(sequence):
L <-- left component of sequence
R <-- right component of sequence
result <-- R + L
return result
endfunction

function decrypt(sequence):
// performs the same swapping operation as the encryption part
return encrypt(sequence)
endfunction
``````

Mixer

This is the most important component of the single round in the DES algorithm. In the mixer we obtain a 64 bit binary sequence. We divide it into 2 parts of 32 bit each. The right part is then expanded using an expansion Permutation Box (E-PBox) and a resulting 48 bit sequence is created.

The resulting 48 bit sequence is used with the key with a non-reversible mathematical function, in this case the mod function to obtain a new 48 bit sequence.

8 Substitution boxes are applied to the 48 bit sequence to reduce it down to 32 bit. Each SBox reduces 6 bit –> 4 bit. Another permutation is applied to the right block.

Finally a XOR (^) operation is performed between left and right parts and the result is stored in the new left part (32 bits). The combination of these pieces are then returned as 64 bit binary sequence which then go to the Swapper.

``````Mixer:
function encrypt(sequence):
L <-- left part of sequence (32 bit)
R <-- right part of sequence (32 bit)

R1 <-- apply expansion PBox on R

// apply non-invertible function
R2 <-- apply non-invertible modular function on R1 using key K_i

// apply substitution boxes on R2 (48 bit --> 32 bit)
R3 <-- apply 8 substitution boxes on R2

// apply XOR (^) on left and right
L1 <-- L ^ R3

// return combined result
return L1 + R3
endfunction

// same steps as encryption
function decrypt(sequence):
return encrypt(sequence)
endfunction
``````

Round

We now define a single round of the DES Cipher which is in fact a single round of the Feistel Cipher.

``````Round:
mixer <-- the mixer component with key k_i
swapper <-- The swapper component part of a single round

function encrypt(sequence)
ciphertext = mixer.encrypt(sequence)
ciphertext = swapper.encrypt(ciphertext)
return ciphertext
endfunction

function decrypt(sequence)
plaintext = swapper.decrypt(sequence)
plaintext = mixer.decrypt(plaintext)
return plaintext
endfunction
``````

We now combine 16 such rounds to form the DES Ciphers where the last round has no Swapper component and the first 15 rounds have Swappers + Mixers. Also we have a key generator which yields 16 different keys for each round.

``````DES:
rounds <-- generate 15 rounds with 15 different keys using the key generator
rounds <-- add a 16th round with just the Mixer component

function encrypt(sequence):
ciphertext <-- initial permutation on sequence
for round in rounds [i = 1... 16]
ciphertext = round.encrypt(ciphertext)
endfor
return final permutation on ciphertext
endfunction

function decrypt(sequence):
plaintext <-- final permutation inverse on sequence
for round in rounds [i = 16... 1] // going in reverse
plaintext = round.decrypt(plaintext)
endfor
return initial permutation inverse on plaintext
endfunction``````

#### Honors Peer-graded Assignment: Real-world use of block cipher operation mode Solution

This exercise is to identify and justify a real-world application of the block cipher operation mode.

##### Conclusion:

I hope this Symmetric Cryptography Peer-graded Assignments Solution would be useful for you to learn something new from this Course. If it helped you then don’t forget to bookmark our site for more peer graded solutions.

This course is intended for audiences of all experiences who are interested in learning about new skills in a business context; there are no prerequisite courses.

Keep Learning!