Highlights
You are to write a program that Implements encryption in simplified DES system described in section
The program will consist of at least two methods. - encrypt(plaintext, key): The plaintext is an integer in the range 0 to 4095 (12 bits) and the key an integer in the range 0 to 511 (9 bits). It returns the ciphertext, which is a 12-bit integer.
A main method or section that prompts the user for a plaintext value and a key value and then prints the ciphertext.
A good approach to writing this is to implement each step in a round as a method. To support this, here is the pseudocode for the various steps along with a method for creating the key schedule.
Note that all variables and parameters are of type integer.
generateKeySchedule(key)
subkeys = integer array of length 4
subkeys[0] = (key & 0b111111110) >> 1;
subkeys[1] = ((key & 0b011111111) << 0>> 9);
subkeys[2] = ((key & 0b001111111) << 1>> 8);
subkeys[3] = ((key & 0b000111111) << 2>> 7);
return subkeys
expand(r)
bit1 = (r & 0b100000) >> 5
bit2 = (r & 0b010000) >> 4
bit3 = (r & 0b001000) >> 3
bit4 = (r & 0b000100) >> 2
bit5 = (r & 0b000010) >> 1
bit6 = (r & 0b000001) >> 0
expandedR = (bit1 << 7>
(bit4 << 3> return expandedR
s1box(n)
s1values = [[0b101, 0b010, 0b001, 0b110, 0b011, 0b100, 0b111, 0b000],
[0b001, 0b100, 0b110, 0b010, 0b000, 0b111, 0b101, 0b011]]
fourBitValue = n & 0b1111
rowIndex = fourBitValue >> 3
columnIndex = fourBitValue & 0b111
return s1values[rowIndex][columnIndex]
s2box(n)
s2values = [[0b100, 0b000, 0b110, 0b101, 0b111, 0b001, 0b011, 0b010],
[0b101, 0b011, 0b000, 0b111, 0b110, 0b010, 0b001, 0b100]]
fourBitValue = n & 0b1111
rowIndex = fourBitValue >> 3
columnIndex = fourBitValue & 0b111
return s2values[rowIndex][columnIndex]
f(r, key)
r = expand(r)
r = r ^ key
rLeft4bits = (r & 0b11110000) >> 4
rRight4bits = (r & 0b1111) >> 0
s1 = s1box(rLeft4bits)
s2 = s2box(rRight4bits)
return (s1 << 3>
This IT Computer Science has been solved by our PhD Experts at My Uni Paper.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.