This article was co-authored by @gums
Introduction
Numerous times we have heard people suggest we should save files to “the cloud”. The cloud storage concept sounds magical although your files exist in physical digital infrastructure in invisible locations. The actual situation reveals that clouds do not exist in reality. Data is stored on powerful servers that belong to companies including Google, Amazon, and Microsoft. Somewhere on the Earth, computers serve as the basis of cloud storage services.
All of your data will remain as basic written strings of information which mirrors regular laptop file storage on another person’s hard disk.
This is why security matters. Server access without proper protection enables users to easily read files while they can spy on messages and steal identity information. The awareness of data storage locations alongside protective measures has become necessary since cyberattacks and breaches now occur more frequently in our world today.
Simple Model: 3 Levels of Data “Protection”
All protective measures have varying levels of effectiveness. The various protective techniques fit into three main categories known as Obfuscation along with Encryption and Hashing methods. The ability to differentiate between these protection methods will enable you to select proper tools while protecting yourself from security misperceptions.
-
Obfuscation: All obfuscation operations boil down to disguising items through straightforward visibility. The cryptography methods include Base64 encoding together with character swaps and the substitution of "password" with "p455w07d." They provide no actual security to your information.
- Use case: Very basic deterrence or data formatting.
- Don’t count on it for: Real protection.
-
Encryption (The Real Deal): Advanced algorithms transform your data into impenetrable noise through combination with undisclosed cryptographic keys. The correct key functions as both the protection and the recovery method to make encrypted data usable. The key possession needed for data decryption protects information from unauthorized access since encryption renders all data unrecognizable.
- Use case: Secure communication, protected storage, safe browsing.
- We will further dive into this next.
-
Hashing (One-Way Lock): Hash functions serve for authentication rather than encryption because they produce fixed-length outputs. The hashing process transforms any provided entry such as a password or file into a predefined output string called a digest. The inputs undergo changes which result in entirely different hash outputs. The functionality of hashing generates non-reversible results since the process operates only in one direction.
- Use case: Data integrity, password verification, digital signatures.
- Not for: Recovering original data.
Why Encryption-And Why “Simple” Can Be Enough
The word encryption typically triggers images of spy films combined with state secrets and elaborate calculation systems. Even though high-drama encryption solutions exist, the standard encryption approaches remain straightforward and not overwhelming.
Fit the Tool for the Job
The high-level encrypted authentication systems are not required by every application or website development and do-it-yourself project. The most important factor is picking a security solution that matches the specific needs. Basic encryption implementation that is properly executed aids in preventing casual unauthorized entry into secure areas.
Small Systems, Big Benefits
Basic security improvements include the use of file passwords for encryption and HTTPS communication encryption. A basic encryption system consisting of a symmetric key demonstrates sufficient ability to provide protection:
Prevent accidental data leaks
Keep logs or messages private from casual observers
Basic security improvements include the use of file passwords for encryption and HTTPS communication encryption. Always keep in mind that a basic encryption system consisting of a symmetric key demonstrates sufficient ability to provide protection.
Old-School Encryption: The Caesar Cipher
Let’s take a step back in time to one of the easiest ciphers ever used—the Caesar cipher. Named after Julius Caesar himself, this method is about as simple as encryption gets, just shift each letter by a fixed number. That’s it.
So, if your secret number is 5, you shift every letter in your message forward by 5 spots in the alphabet:
- A → F, B → G,… U → Z, V → A, etc.
Let’s try it on the phrase “HELLO WORLD”:
Shift each letter by 5 and we get “MJQQT BTWQI”, an encrypted message!
But here's the thing—while that might look mysterious at first glance, it's not exactly airtight. A determined decoder or just someone with too much free time could just try all 26 possible shifts until the message makes sense.
A code snippet of Caesar Cipher:
string CeasarCiper(const string& plaintext, int shifts) {
string decrypted;
decrypted.reserve(plaintext.length());
for(char c : plaintext) {
decrypted.push_back(shift(c, shifts));
}
return decrypted;
}
char shift(char c, int shifts) {
if (isalpha(c)) {
shifts = (shifts % 26 + 26) % 26;
char base = isupper(c) ? 'A' : 'a';
return base + ((c - base + shifts) % 26);
} else {
return c;
}
}
The bruteforce code…
void BruteForceCaesarCipher(string encrypted) {
for(int shifts = 0; shifts < 26; shifts++) {
cout << CeasarCiper(encrypted, -shifts) << endl;
}
}
This type of brute-force attack is so easy—which is why modern security has moved far, far beyond this.
Still, it’s a great starting point for learning how encryption works: a key (in this case, the number 5) transforms the original message into something unreadable... until it’s unlocked again.
The Vigenère Cipher: Simple, Yet Powerful
Before we delve into the mechanics of the Vigenère cipher, let's take a brief journey through its history. The cipher commonly known today as the "Vigenère cipher" was first described by Italian cryptographer Giovan Battista Bellaso in 1553. Bellaso introduced a method of Polyalphabetic substitution using a keyword to determine the shifting of letters, enhancing the security over simpler ciphers like Caesar's.
However, in 1586, French diplomat and cryptographer Blaise de Vigenère published a similar cipher, which—due to historical circumstances, became more widely known and associated with his name. Thus, the cipher is often attributed to Vigenère, despite Bellaso's earlier work.
How the Vigenère Cipher Works
Choose a keyword - the keyword will determine the shift for each letter in your plaintext.
Keyword: “prosonly”Choose the plaintext message you want to encrypt.
Plaintext: “legendslangnakakaalam”Repeat the Keyword - extend the keyword so that its length matches the length of the plaintext. This is done by repeating the keyword as many times as necessary.
Extended Keyword: “prosonlyprosonlyproso”Choose a key for the vigenère table - let’s call it table key, make the table key so that no characters are repeating, this will limit the characters of our table key to 26—but up to 95 if we include all the printable ASCII characters.
Table Key: “sparcz”Create the first row for the table - in using only the alphabets, we use our table key, put the table key ahead of all the letters in the alphabet, and put the unused letters in the succeeding slots.
First Row of the Table (alphabets only): “sparczbdefghijklmnoqtuvwxy”Create the vigenère table using the first row - we have our first row, now we must shift that row to the left, then make it the second row, and use that second row as a basis for the third row—shifting it left and then making it the third, and so on until you have a 26 x 26 or 95 x 95 table.
Encryption Algorithm:
Locate the key-row: For each plaintext character, take the corresponding letter in your extended keyword, find the row in your 26×26 (or 95×95) table whose first character matches that keyword letter.
Locate the plaintext-column: In the first row (your “Table Key” alphabet), find the column whose header equals the plaintext character.
Read off the cipher-letter: The intersection cell of that row and column is your encrypted character, in this case, it’s “m”.
Repeat for every character (spaces and punctuation can be left unchanged, or mapped via your ASCII table).
Now we have our encrypted message: “mhaefxlkrtantznjrzdae”
Decryption Algorithm:
For decrypting, you have to have the table and the key.
- Locate the key-row (same as in encryption).
- Scan across that row to find the ciphertext character.
- Trace upward to the first‐row header: that header letter is your recovered plaintext
- Repeat for every character.
Here is a simple code snippet of encryption using vigenère cipher:
string encrypt(const vector& table,
const string& key,
const string& message) {
string out;
out.reserve(message.size());
string longKey = formatKey(key, message);
for (size_t i = 0; i < message.size(); ++i) {
int row = table[0].find(message[i]);
int col = table[0].find(longKey[i]);
out.push_back(table[row][col]);
}
return out;
}
And the decryption is almost the same.
string decrypt(const vector& table,
const string& key,
const string& encrypted) {
string out;
out.reserve(encrypted.size());
string longKey = formatKey(key, encrypted);
for (size_t i = 0; i < encrypted.size(); ++i) {
int row = table[0].find(longKey[i]);
for (int col = 0; col < 26; ++col) {
if (table[row][col] == encrypted[i]) {
out.push_back(table[0][col]);
break;
}
}
}
return out;
}
When—and How—to Use Vigenère in Small Projects
The Vigenère cipher, with its straightforward implementation, serves as an great tool for:
- Personal note encryption: Keeping journal entries or personal thoughts private.
- Simple script obfuscation: Adding a layer of obscurity to scripts or configuration files. Educational purposes: Understanding the basics of encryption and the evolution of cryptographic techniques.
Its simplicity allows for quick implementation without the need for complex libraries or systems.
Limitations— Vulnerable to Frequency Analysis on Long Texts
While the Vigenère cipher offers more complexity than a simple Caesar cipher, it's not impervious to cryptanalysis. Techniques like the Kasiski examination and the Friedman test can determine the key length, and once that's known, frequency analysis can be applied to each subset of the ciphertext . This makes the cipher susceptible, especially when used on longer texts with repeating patterns.
Practical Applications:
- Use it for short, non-critical data: Ideal for obfuscating information that doesn't require high security.
- Combine with other methods: For added security, consider layering the Vigenère cipher with other encryption or obfuscation techniques.
- Educate and experiment: Use it as a stepping stone to understand more advanced encryption methods.
Remember, while the Vigenère cipher is a fascinating piece of cryptographic history, modern security demands often require more robust solutions. Use it wisely, and always assess the security needs of your specific application.
Your First Step To Encryption
The concept of encryption appears challenging at first but in reality, it is simple to understand as you have learned. The essential usage of encryption requires no expertise beyond its basic understanding. Implementation of basic encryption creates a transformation that protects your sensitive information through encryption yet keeps it from becoming accessible to unauthorized users.
There exists a vast collection of contemporary algorithms to investigate for those who want to advance, which includes AES for rapid secure file encryption, RSA for web-based secret sharing and ECC which is designed for efficient encryption in constrained spaces such as mobile applications or IoT devices.
The fact is that you don’t need to feel pressured to master all of it at once.
The most important part is starting. Just pick a simple cipher and simply use it in your next project. Take the opportunity to integrate encryption into something real. Even basic encryption is already a huge step forward, which is leagues better than having no protection at all.