Cryptography and Steganography

A brief introduction to cryptography and steganography

Gumn4m1
4 min readJun 14, 2024

Cryptography:~

The study of encryption and encoding schemes which includes encoding-decoding , encrypting-decrypting, and hashing is called cryptography

Encoding:
This is a technique of transforming data from intelligible to another (unintelligible) form

Decoding:
This is the technique of transforming data from unintelligible to intelligible form

Encryption:
It is a cryptographic technique for protecting the data confidentiality and preserving the usability of the data by using key or a pair of key to transform data.

Decryption:
It is the technique for transforming encrypted unintelligible data to intelligible form using key or pair of keys

Hashing:
It is the process of generating a fixed size output from an input of variable size using mathematical formulas known as hashing function.
Hashes cannot be reversed

Techniques that are used for deciphering a message:
1. Cryptanalysis
2. Bruteforce

Cryptanalysis:
Study of Deciphering message without any knowledge of enciphering details is called cryptanalysis. The study of cryptography and cryptanalysis is also known as cryptology.

Bruteforce:
Everything is known except the key , then we can use bruteforce method

Encryption scheme can be “Unconditionally secure” if,
It doesn’t contain enough information to determine the corresponding plaintext uniquely, which means no matter how much time an opponent has, it is impossible for him to break or decrypt the message simply because the required information is not there.

but it is practically not possible.

An encryption scheme can be called “Computationally secure” if
i. The cost of breaking the cipher exceed the cost of the encrypted information
ii. The time required to break the cipher exceeds the useful time of the information

Encryption:
5 ingredient of encryption scheme
i. Plaintext = Input text to encrypt
ii. Encryption algorithm = algorithm to encrypt
iii. Secret key
iv. Cipher text = output or encrypted text
v. Decryption algorithm = reverse algorithm of the encryption algorithm

Classification:
Cryptographic systems are classified along 3 independent dimensions
1. Type of operation:
i. Substitution
ii. Transposition
2. Number of key used:
i. Symmetric key
ii. Asymmetric key
3. Processing of plaintext:
i. Block cipher
ii. Stream cipher

— Substitution technique —

Caeser cipher:
c = E(3,p) = (p+3) mod 26

Caeser cipher wheel

Monoalphabetic Cipher:
— Permutation of the character set is used
eg. S = {a,b,c}
then there are 6 possibilities
abc , acb , bac , bca, cab , cba

Message = “bac” , Encryption perm = {c , a , b} then cipher text = “acb”. In caeser cipher only 25 keys are possible but in case of Monoalphabetic cipher 26! keys are possible if the character set is only alphabets

— Transposition cipher —

Rail fence cipher:
“meet me after the party” = “meetmeaftertheparty”

m e m a t r h p r y
e t e f e t e a t

= “mematrhpryetefeteat”

Symmetric encryption
Encryption that uses a single key for both encryption and decryption

Asymmetric encryption
Encryption that uses different key or pair of key for encryption and decryption

Block cipher
Encryption in which a chunk of text or block is processed at a time

Stream cipher
Encryption that processes single character at a time and process continuously

Steganography :~

Steganography is the technique of hiding data within an ordinary, nonsecret file or message to avoid detection

Simple and historical examples of steganography

i. The sequence of first letter of each word spells out a hidden message
ii. Character marking (not visible marking unless the paper held at an angle to bright light)
iii. Invisible ink
iv. Pin puncture
v. Typewriter correction ribbon

Hiding message in a image :
eg.

Reference: https://www.geeksforgeeks.org/image-steganography-in-cryptography/

def hide_text(image_path, secret_text, output_path):
# Open the image
image = Image.open(image_path)

# Convert the secret text to binary
binary_secret_text = ‘’.join(format(ord(char), ‘08b’) for char in secret_text)

# Check if the image can accommodate the secret text
image_capacity = image.width * image.height * 3
if len(binary_secret_text) > image_capacity:
raise ValueError(“Image does not have sufficient capacity to hide the secret text.”)

# Hide the secret text in the image
pixels = image.load()
index = 0
for i in range(image.width):
for j in range(image.height):
r, g, b = pixels[i, j]

# Modify the least significant bit of each color channel
if index < len(binary_secret_text):
r = (r & 0xFE) | int(binary_secret_text[index])
index += 1
if index < len(binary_secret_text):
g = (g & 0xFE) | int(binary_secret_text[index])
index += 1
if index < len(binary_secret_text):
b = (b & 0xFE) | int(binary_secret_text[index])
index += 1

pixels[i, j] = (r, g, b)

# Save the image with the hidden secret text
image.save(output_path)

In this algorithm r,g,b values of each pixel is stored in a variable and then “AND” operation with 0xFE or 254 or 0b11111110 value to make the last bit 0 and “OR” operation with the corresponding index placed character of the secret message’s binary string is done to change the last value

In this operation a single bit of RGB is changes which cannot be differentiated without checking the RGB values

--

--