Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit 360e56b

Browse files
author
Matt Manzi
committed
Cleaned up README and files
1 parent 4b681e0 commit 360e56b

File tree

9 files changed

+193
-271
lines changed

9 files changed

+193
-271
lines changed

README.md

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# DS-DEA
22
_Matt Manzi_
3-
_Project 2 of CMSC 487, Spring 2020._
43

54
An implementation of the Simplified Data Encryption Standard (S-DES) and Double Simplified Data Encryption Algorithm (DS-DEA).
65

7-
This implementation includes code to run meet-in-the-middle and brute force attacks on the hardcoded set of plaintext/ciphertext pairs listed below:
8-
```
9-
0x42/0x52, 0x72/0xf0, 0x75/0xbe, 0x74/0x69, 0x65/0x8a
10-
```
6+
This implementation includes code to run meet-in-the-middle and brute force attacks on a hardcoded set of plaintext/ciphertext pairs listed in the following section.
117

128
## Installation and Usage
139

@@ -18,7 +14,13 @@ Once installed, enter the top-level project directory. Run the code with the fo
1814
swift run DSDEA test|mitm|brute|decrypt
1915
```
2016

21-
## Project Answers
17+
## Attack Tests
18+
19+
The following plaintext/ciphertext pairs listed below correspond to a key pair combination:
20+
```
21+
0x42/0x52, 0x72/0xf0, 0x75/0xbe, 0x74/0x69, 0x65/0x8a
22+
```
23+
The keys can be determined using the provided code. See below for expected results.
2224

2325
### Found Keys
2426

@@ -34,19 +36,6 @@ Below are the time for one run of each of meet-in-the-middle and brute force att
3436
* MITM: **1.176 seconds**
3537
* Brute Force: **3:30.07 minutes**
3638

37-
<img src="times.png" alt="The time elapsed for a single meet-in-the-middle and brute force attack, respectively." />
38-
39-
### Decrypted Message
40-
41-
The given ciphertext:
42-
```
43-
0x586519b031aaee9a235247601fb37baefbcd54d8c3763f8523d2a1315ed8bdcc
44-
```
45-
decrypted with the keys found above will produce the (UTF-8-enocded) plaintext:
46-
```
47-
Congratulations on your success!
48-
```
49-
5039
### Weak Keys
5140

5241
There are **4** weak keys for S-DES:

Sources/DSDEA/DSDEA.swift

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Algorithm (DS-DEA).
55
//
66
// Created by Matt Manzi on 3/1/20.
7-
// Project 2 of CMSC 487, Spring 2020.
87
//
98

109
import Foundation
@@ -14,60 +13,60 @@ let IV: UInt8 = 0x9c
1413

1514
/// The user-facing portion of DS-DEA which uses double S-DES in CBC mode.
1615
public class DSDEA {
17-
16+
1817
/// An instance of the core SDES functionality class.
1918
private static let core = SDESCore()
20-
19+
2120
/**
2221
Encrypts a data array using the provided keys, based on the DS-DEA specification in CBC mode.
23-
22+
2423
- Postcondition: The returned array will be the same size as the original.
25-
24+
2625
- Parameter data: The data to encrypt.
2726
- Parameter keys: The two keys to encrypt the data with.
28-
27+
2928
- Returns: The `keys`-encrypted data.
3029
*/
3130
public static func encrypt(_ data: [UInt8],
3231
with keys: [UInt16]) -> [UInt8] {
3332
var c: UInt8 = IV
3433
var out: [UInt8] = []
35-
34+
3635
// double-encrypt each block
3736
for i in data {
3837
c = core.encrypt(core.encrypt(i ^ c, with: keys[0]), with: keys[1])
3938
out.append(c)
4039
}
41-
40+
4241
return out
4342
}
44-
43+
4544
/**
4645
Decrypts a data array using the provided keys, based on the DS-DEA specification in CBC mode.
47-
46+
4847
- Postcondition: The returned array will be the same size as the original.
49-
48+
5049
- Parameter data: The data to decrypt.
5150
- Parameter keys: The two keys to decrypt the data with.
52-
51+
5352
- Returns: The `keys`-decrypted data.
5453
*/
5554
public static func decrypt(_ data: [UInt8],
5655
with keys: [UInt16]) -> [UInt8] {
5756
var c: UInt8 = IV
5857
var p: UInt8 = 0x00
5958
var out: [UInt8] = []
60-
59+
6160
// double-decrypt each block
6261
for i in data {
6362
p = core.decrypt(core.decrypt(i, with: keys[1]), with: keys[0]) ^ c
6463
out.append(p)
65-
64+
6665
// keep the current ciphertext for the XOR for the next decryption
6766
c = i
6867
}
69-
68+
7069
return out
7170
}
72-
71+
7372
}

0 commit comments

Comments
 (0)