# Encryption-Decryption

**Joel Lozano**

- Published on

### 💡Key Ideas:

There are two major types of encryption schemes are widely used:

symmetric encryption (where a single secret key - imagine password is used to encrypt and decrypt data)

asymmetric encryption (where a public key cryptosystem is used and encryption and decryption is done using a pair of public and corresponding private key - imagine account name and password).

Symmetric encryption

- Take a message (plain text)
- Encrypt it using secret key (convert it to cipher text)
- Decrypt it using secret key (back to plain text)
- PS: ciphertext: a binary sequence, unreadable by humans and by design cannot be decrypted without the decryption key.

### Asymmetric encryption

For each party, two related keys known as key-pairs are created: a public and a private key. Data encrypted by a public key is decrypted by the corresponding private key.

Typically, many systems use a hybrid encryption scheme which combines symmetric and asymmetric encryption like this:

- For the encryption a random symmetric key sk is generated, the message is symmetrically encrypted by sk, then sk is asymmetrically encrypted using the recipient's public key.
- For decryption, first the sk key is asymmetrically decrypted using the recipient's private key, then the ciphertext is decrypted symmetrically using sk.

### Popular Public Key Cryptosystems

RSA is one of the oldest widely used for secure data transmission. Based on the math of modular exponentiations, it's computational difficulty comes from the integer factorization problem.

ECC the basis of Bitcoin, Ethereum and many blockchain account systems (public/private keys are basically addresses on blockchains). Based on the math of algebraic structures of elliptic curves over finite fields, it's computational difficulty comes from the elliptic curve discrete logarithm problem (ECDLP)

ElGamal also widely used In cryptography and based from the Diffie–Hellman key exchange

And variants like: RSA sign, RSA encrypt / decrypt, ECDH key exchange and ECDSA and EdDSA signatures.

#### Interesting notes

Note that both RSA and ECC cryptosystems are not quantum-safe, which means that if someone has enough powerful quantum computer, he will be able to derive the private key from given public key in just few seconds.

### 🔗Links:

Cryptobook - Encryption: Symmetric and Asymmetric

PSE Core Program 2023 - Encryption

🛠️ Build and Practice: Try out Asymmetric Encryption - Online Demo Implement a public-private encryption algorithm scheme in a popular language of your choice 🕹️ Implement the following game :

A group of 4 friends want to store a picture that is only revealed after the picture is revealed with the approval of all of them. Implement it as following:

- A picture is encrypted using each friend public key (keep track of the order)
- The picture is revealed by having each friend decrypt the image using their private key (in reverse order)"