ECB Encryption
A simple encryption method that allows parallel encryption and tolerates lost/damaged blocks. However, patterns in plaintext are repeated in ciphertext. Additionally, if 2 messages are the same, they will have the same ciphertext.
CBC Encryption
A fast and simple encryption method that does not repeat plaintext patterns in ciphertext. Additionally, allows multi use keys by adding a unique IV (key, IV) for each message. However, there is no parallel encryption and it is insecure against active attacks.
CBC vs ECB Encryption

To compare CBC and ECB encryption, I encrypted the image above with both encryption methods and key = 123456789.
The above image was encrypted with CBC and we can see that there are no patterns to see, only noise.
The above image was encrypted with ECB and shows clear patterns and shapes similar to the original image.
Compared to CBC, ECB is less secure because clear patterns are visible.
RSA Encryption
RSA encryption is used to get symmetric session keys and has the following property: secret_key(public_key(message)) = message = public_key(secret_key(message))
The process of RSA key generation is as follows:
- Define large primes
pandq - Calculate
n=p*q - Calculate
phin=(p-1)*(q-1)using the BIGNUM functionBN_mul(n,p,q,context)
- Since 1 is not a BIGNUM, this is done as
phin = (p=hex of p -1) * (q=hex of q -1)
- Pick an
ethat is relatively prime tophin(ie their greatest common divisor is 1 ) - Calculate a unique private key
dsuch thated = 1 % phinusing the BIGNUM methodBN_mod_inverse(d,e,phin,context)sincedis the multiplicative inverse ofe % phin - The public key is then
(e,n)and the secret key is(d,n)
To encrypt a message:
cipher = message ^ e % n
To decrypt a message:
cipher ^ d % n = (message ^ e)^d = message
Using the above process and this c code, I determined
d = 3587A24598E5F2A21DB007D89D18CC50ABA5075BA19A33890FE7C28A9B496AEB.
After converting the plaintext message A top secret! to hex, I encrypted it using the public key (e,n) and cipher = message ^ e % n. Then I decrypted it using the private key d and message = cipher ^ d % n, which gives the hex value of A top secret!, verifying the encryption.