# DES (Data Encryption Standard)

The DES is a symmetric-key algorithm for the encryption of digital data.

### Basic Encryption/Decription with OpenSSL <a href="#basic-encryptiondecription-with-openssl" id="basic-encryptiondecription-with-openssl"></a>

#### 1. Prepare Plain Text File <a href="#id-1-prepare-plain-text-file" id="id-1-prepare-plain-text-file"></a>

At first, we create a text file which contains a simple word "hello".

```
echo hello > hello.txt
```

#### 2. Encrypt the Plain Text File <a href="#id-2-encrypt-the-plain-text-file" id="id-2-encrypt-the-plain-text-file"></a>

Using `openssl`, we can encrypt the file using **DES** algorithm. We're asked the password so enter the new one.

```
openssl des -e -in hello.txt -out encrypted.enc
```

After encryption, we can send the encrypted file to someone else. And someone can decrypt it with the DES algorithm.

#### 3. Decrypt the Encrypted File <a href="#id-3-decrypt-the-encrypted-file" id="id-3-decrypt-the-encrypted-file"></a>

In the decryption process, we can also use the almost same command but specify `-d (decrypt)` option instead of `-e (encrypt)`. We'll be asked the password which is set when encryption so enter the same password.

```
openssl des -d -in encrypted.enc -out decrypted.txt
```

After decryption, confirm that the content of the `decrypted.txt` is the same as that of the original plain `hello.txt`.

```
cat decrypted.txt
# hello
```

### Triple DES <a href="#triple-des" id="triple-des"></a>

**Triple DES (3DES)** applies the **DES** cipher algorithm three times to each data block.\
This encryption/description process with `openssl` is almost the same as that of **DES** so I'll write it briefly here

```
# Encryption
openssl des -e -in hello.txt -out encrypted.enc

# Decryption
openssl des -d -in encrypted.enc -out decrypted.txt
```
