140 likes | 216 Views
Programming DES. CPTR 427. Outline. Top Level Design Design Decisions Operations to write Putting it together. Top Level Design. Depending on whether we are encrypting or decrypting we set the input files accordingly.
E N D
Programming DES CPTR 427
Outline • Top Level Design • Design Decisions • Operations to write • Putting it together
Top Level Design Depending on whether we are encrypting or decrypting we set the input files accordingly. Create a “Keys” object that generates all the round keys used by DES in the order needed to encrypt or decrypt This is the hard part! Let’s delve into the design decisions that have to be made first.
Design Decisions • Representing Data consistently • BitSets (Java) • BitArray (C#) • UInt64 (C#) • Long (Java) • Operations • Permutations • Expansions/Contractions • XOR operations • Odd side consideration: • we work with 4/6/28/32/48/56/64 bit values
BitSets and BitArrays • Advantages: • Easy to perform permutations – bit level access • Can easily expand or contract length… • … can express arbitrary size • Has XOR operation • Bit position easy to understand • Disadvantages • Data is not in this format natively… • Must convert between bytes and BitSets/BitArrays • SLOW!
Long and UInt64 • Advantages • Bytes convert easily to long or unsigned int64 • Easy shift and XOR operations • Unnecessary to convert data to a new object type • THIS IS THE WAY IT SHOULD BE DONE… • Disadvantages • Odd size information location (e.g. where does my 56 bits start?) • Permutations are no longer intuitive
What format? • For better or worse, I chose long in Java to avoid and delt with the permutation issues – in retrospect that was a good choice because it made my work easier because I didn’t have to process data in two very different formats. My Advice: • Chose long/UInt64 and deal with the selection problem instead.
Operations • Permutations • Left Circular Shifts • Swaps
Operations (Single Round) • XOR • S-Box operations
Operations to Write • Simple Ops • Permutations (with expansion or contraction + odd sizes) • Separate left circular shifts within a 64 bit long/UInt64 • Swaps (first 32 bits for second 32 bits) • XOR (Native) • S-Box Operations • Named Ops • Data: IP and IP-1, E, S-Box, P, XOR • Key: PC-1, PC-2, XOR, Left Circular shifts
Permutations • Defined by • Data Input • Size of input data • Data Output • Size of output data • Mapping: input output • That takes care of IP, IP-1, E, P, PC-1, PC-2 • Leaving: S-Box, Left Circular Shifts, swap32 and XOR public UInt64 perm(UInt64 input, intinsize, int outsize, int[] map)
Permutation Logic Move a bit from position x in the input to position y in the output.
The rest of the Ops public UInt64 leftShift(UInt64 input, intshiftAmount) public UInt64 swap32(UInt64 input) public UInt64 sBox(UInt64 input)
Putting it all together… • The entire goal of this project is for you to put this together using the instructions from the Stallings textbook. • Use the notes and the program skeleton provided!