Cryptography
Cryptography
WHAT IS CRYPTOGRAPHY?
1. Symmetric Encryption
2. Asymmetric Encryption
WHAT IS SYMMETRIC ENCRYPTION?
As shown below in the figure, the key which is being used for encrypting
the original message is decrypting the ciphertext. The key must be kept
private and be known only to the sender and the receiver.
For example, if Paul wants to send a simple message to Jane, they need
to have a single encryption key that both of them must keep secret to
prevent snooping by malicious actors. If the message “I am ready” is
converted to ciphertext using a specific substitution cipher by Paul, Jane
must be aware of the substitution shift to decrypt the ciphertext once it
reaches her.
• Step 5: Jane uses the secret key to decrypt the message that
was already present with her
Following the above process, Paul and Jane communicate privately
without the fear of anyone lurking on the route. Since only both of them
have the secret key needed to encrypt and decrypt the message, no third
party who can intercept the encrypted message can break into it.
Now that you have a foundation, it’s time to walk you through its
applications.
• SSL/TLS Handshake:
However, the tricky part comes when Ryan needs to receive the
decryption key for the encrypted data.
You face a critical problem here when it comes to the key exchange. The
encrypted messages in transit are not a risk to either sender or receiver
since unauthorized people can’t read the contents. But the decryption
key, on the other hand, if intercepted, exposes all the information Joe
has to disclose to Ryan.
This is the dilemma asymmetric encryption has fixed because of its multi-
key architecture.
WHAT IS ASYMMETRIC ENCRYPTION?
As you can see in the above image, using different keys for encryption
and decryption has helped avoid the problem of key exchange, as seen
in the case of symmetric encryption.
For example, if Alice needs to send a message to Bob, both the keys,
private and public, must belong to Bob.
The process for the above image is as follows:
As shown below, anyone who has the postal address of the receiver
(public key in our case) can send any message they want.
However, only the receiver can read all his/her messages thanks to the
mailbox key that no other person can have.
This eliminates the need to exchange any secret key between sender
and receiver, thereby reducing the window of exploitation.
Now that you understand the base terminology and process behind
asymmetric key cryptography.
XOR is a cheap way to encrypt data with a password. Any data can be
encrypted using XOR as shown in this Python example:
EXPLOITING XOR ENCRYPTION
Single Byte XOR Encryption
Single Byte XOR Encryption is trivial to bruteforce as there are only 255
key combinations to try.
Multibyte XOR gets exponentially harder the longer the key, but if the
encrypted text is long enough, character frequency analysis is a viable
method to find the key. Character Frequency Analysis means that we
split the cipher text into groups based on the number of characters in the
key. These groups then are bruteforced using the idea that some letters
appear more frequently in the english alphabet than others.
CAESAR CIPHER/ROT 13
The Caesar Cipher or Caesar Shift is a cipher which uses the alphabet in
order to encode texts.
ROT13 is the same thing but a fixed shift of 13, this is a trivial cipher to
bruteforce because there are only 25 shifts.
VIGENERE CIPHER
DECRYPTION
STRING HASHING
The idea is that each hash should be unique to the text or data (although
sometimes it isn’t). For example, the hash for “dog” should be different
from other hashes.
You can use command line tools or online resources such as this one.
Example:
Generally, when verifying a hash visually, you can simply look at the first
and last four characters of the string.
FILE HASHING
How can we determine the hash of a file? You can use the md5sum
command (or similar).
$ md5sum samplefile.txt
3b85ec9ab2984b91070128be6aae25eb samplefile.txt
HASH COLLISIONS