Americas

  • United States

Asia

Oceania

Josh Fruhlinger
Contributing writer

What is cryptography? How algorithms keep information secret and safe

Feature
May 22, 202213 mins
EncryptionInternet SecurityNetwork Security

Public keys, private keys, and hash functions make the secure internet possible.

5 cryptography and data protection
Credit: Getty Images

Cryptography definition

Cryptography is the art of keeping information secure by transforming it into form that unintended recipients cannot understand. In cryptography, an original human readable message, referred to as plaintext, is changed by means of an algorithm, or series of mathematical operations, into something that to an uninformed observer would look like gibberish; this gibberish is called ciphertext.

Cryptographic systems require some method for the intended recipient to be able to make use of the encrypted message—usually, though not always, by transforming the ciphertext back into plaintext. 

Cryptography vs. cryptology vs. encryption

Before we move into the meat of this article, let’s define a couple terms related to cryptography. The syllable crypt may make you think of tombs, but it comes from a Greek word that means “hidden” or “secret.” Cryptography literally means “secret writing.” Cryptology, meanwhile, means something like “knowledge of secrecy”; if cryptography is the practice of writing secret messages, then cryptology is the theory, although the two words are often used interchangeably. Encryption—“making secret”—is what we call the process of turning plaintext into ciphertext Encryption is an important part of cryptography, but doesn’t encompass the entire science. Its opposite is decryption.

One important aspect of the encryption process is that it almost always involves both an algorithm and a key. A key is just another piece of information, almost always a number, that specifies how the algorithm is applied to the plaintext in order to encrypt it. In a secure cryptographic system, even if you know the method by which some message is encrypted, it should be difficult or impossible to decrypt without that key. Keep algorithms and keys in your mind, because they’ll be important as we move on.

History of cryptography

This is all very abstract, and a good way to understand the specifics of what we’re talking about is to look at one of the earliest known forms of cryptography. It’s known as the Caesar cipher, because Julius Caesar used it for his confidential correspondence; as his biographer Suetonius described it, “if he had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet … If anyone wishes to decipher these, and get at their meaning, he must substitute the fourth letter of the alphabet, namely D, for A, and so with the others.”

Suetonius’s description can be broken down into the two cryptographic elements we’ve discussed, the algorithm and the key. The algorithm here is simple: each letter is replaced by another letter from later in the alphabet. The key is how many letters later in the alphabet you need to go to create your ciphertext. It’s three in the version of the cipher Suetonius describes, but obviously other variations are possible—with a key of four, A would become E, for instance.

A few things should be clear from this example. Encryption like this offers a fairly simple way to secretly send any message you like. Contrast that with a system of code phrases where, say, “Let’s order pizza” means “I’m going to invade Gaul.”  To translate that sort of code, people at both ends of the communication chain would need a book of code phrases, and you’d have no way to encode new phrases you hadn’t thought of in advance. With the Caesar cipher, you can encrypt any message you can think of. The tricky part is that everyone communicating needs to know the algorithm and the key in advance, though it’s much easier to safely pass on and keep that information than it would be with a complex code book.

The Caesar cipher is what’s known as a substitution cipher, because each letter is substituted with another one; other variations on this, then, would substitute letter blocks or whole words. For most of history, cryptography consisted of various substitution ciphers deployed to keep government and military communications secure. Medieval Arab mathematicians pushed the science forward, particularly the art of decryption—once researchers realized that certain letters in a given language are more common than others, it becomes easier to recognize patterns, for instance. But most pre-modern encryption is incredibly simple by modern standards, for the obvious reason that, before the advent of computers, it was difficult to perform mathematical transformations quickly enough to make encryption or decryption worthwhile.

In fact, the development of computers and advances in cryptography went hand in hand. Charles Babbage, whose idea for the Difference Engine presaged modern computers, was also interested in cryptography. During World War II, the Germans used the electromechanical Enigma machine to encrypt messages—and, famously, Alan Turing led a team in Britain that developed a similar machine to break the code, in the process laying some of the groundwork for the first modern computers. Cryptography got radically more complex as computers became available, but it remained the province of spies and generals for several more decades.

Principles of cryptography

Before we move on here to modern cryptography, let’s pause to discuss two important principles that underlie it. The first is what’s come to be known as Kerckhoffs’s principle, named after the 19th century Dutch cryptographer Auguste Kerckhoffs. Remember, as we said, any cryptographic system involves both an algorithm and a key. Kerckhoffs believed that “a cryptographic system should be secure even if everything about the system, except the key, is public knowledge.”

Now, these were the days when cryptography had almost entirely military applications. The idea here is that, while it would be nice to keep your cryptographic system a secret, your opponent will almost certainly eventually figure it out. Claude Shannon, a World War II cryptographer who would go on to be a pioneer in information theory, put it more succinctly: “The enemy knows the system.” What Kerckhoffs and Shannon are getting at is that you want to design an algorithm that doesn’t need to be a secret in order to successfully conceal information.

That said, in today’s world, the public nature of cryptographic algorithms is seen as something good in and of itself, rather than an unavoidable evil. Standard cryptographic algorithms have been widely studied and stress-tested, and trying to come up with your own private algorithms is doomed to failure as security through obscurity usually is.  

What you do need to keep secret is your cryptographic key. We’ll get to the mathematics of how that works in a moment, but for now, we’ll touch on another cryptographic principle that makes that math possible: a reliance on one-way functions, mathematical operations that are very difficult to reverse. The classic example of a one-way function is the multiplication of two very large prime numbers together. While that calculation is simple to do, if you only had the end result, it would be very difficult, verging on impossible, to figure out the original two prime numbers. The question of whether any function can truly be one-way is debated by mathematicians, but many are irreversible in practice at the limits of our current computing power, so we’ll leave that question aside as we move on.

Cryptography in network security

It was the formation of the first computer networks that started civilians thinking about the importance of cryptography. Computers were talking to each other over the open network, not just via direct connections to one another; that sort of networking was transformative in many great ways, but also made it trivially easy to snoop on data traveling across the network. And with financial services being an early use case for computer communication, it was necessary to find a way to keep information secret.

IBM led the way in the late 1960s with an encryption method known as “Lucifer”, which was eventually codified by the US National Bureau of Standards as the first Data Encryption Standard (DES). As the internet began to grow in importance, more and better encryption was needed, and today a significant portion of data flying around the world is encrypted using varying techniques that we’ll discuss in more detail in a moment.

What is cryptography used for?

We’ve already discussed some of the specific applications of cryptography, from keeping military secrets to transmitting financial data safely across the internet. In the bigger picture, though, there are some broad cybersecurity goals that we use cryptography to help us achieve, as cybersecurity consultant Gary Kessler explains. Using cryptographic techniques, security pros can:

  • Keep the contents of data confidential
  • Authenticate the identity of a message’s sender and receiver
  • Ensure the integrity of the data, showing that it hasn’t been altered
  • Demonstrate that the supposed sender really sent this message, a principle known as non-repudiation

You may recognize some of these principles from variations of the CIA triad. The first of these uses is the obvious one—you can keep data secret by encrypting it. The others take a bit of explanation, which we’ll get into as we describe the different types of cryptography.

What are the types of cryptography?

There are numerous cryptographic algorithms in use, but in general they can be broken into three categories: symmetric cryptography, asymmetric cryptography, and hash functions. Each has its own role to play within the cryptographic landscape.

Symmetric cryptography. The Caesar cipher we discussed above is a great example of symmetric cryptography. In the example we used, if encrypted messages were being exchanged between Caesar and one of his centurions, both parties would have to know the key—in this case, how many letters forward or backwards in the alphabet you need to move to transform plaintext to ciphertext or vice versa. That’s what makes it symmetrical. But the key needs to stay a secret between the two of them, which is why this is sometimes also called secret key cryptography. You couldn’t send the key along with the message, for instance, because if both fell into enemy hands the message would be easy for them to decipher, defeating the whole purpose of encrypting it in the first place. Caesar and his centurion would presumably have to discuss the key when they saw each other in person, though obviously this is less than ideal when wars are being fought over long distances.

Symmetric cryptography is widely used to keep data confidential. It can be very useful for keeping a local hard drive private, for instance; since the same user is generally encrypting and decrypting the protected data, sharing the secret key is not an issue. Symmetric cryptography can also be used to keep messages transmitted across the internet confidential; however, to successfully make this happen, you need to deploy our next form of cryptography in tandem with it.

Asymmetric cryptography. Caesar may have been able to confer with his centurions in person, but you don’t want to go into your bank and talk to the teller just to learn what the private key is for encrypting your electronic communication with the bank—that would defeat the purpose of online banking. In general, in order to function securely, the internet needs a way for communicating parties to establish a secure communications channel while only talking to each other across an inherently insecure network. The way this works is via asymmetric cryptography, which is sometimes called public key cryptography.

In asymmetric cryptography, each participant has two keys. One is public and is sent to anyone the party wishes to communicate with. That’s the key used to encrypt messages. But the other key is private, shared with nobody, and it’s necessary to decrypt those messages. To use a metaphor: think of the public key as opening a slot on a mailbox just wide enough to drop a letter in. You give that key to anyone who you think might send you a letter so they can open the slot and deliver the envelope. The private key is what you use to open the mailbox so you can get the letters out.

The mathematics of how you can use one key to encrypt a message and another to decrypt it are where the idea of one-way functions that we discussed above come into play: the two keys should be related to each other mathematically such that it’s easy to derive the public key from the private key but not vice versa. For instance, the private key might be those two very large prime numbers, which you’d multiply together to get the public key. The Infosec Institute has a deep dive if you’re interested.

The computations needed for asymmetric cryptography are much more complex and resource intensive that those behind symmetric infrastructure. Fortunately, you don’t need to use it to protect every message you send online. Instead, what usually happens is that one party will use symmetric cryptography to encrypt a message containing yet another cryptographic key. This key, having been safely transmitted across the insecure internet, will then become the private key that encodes a much longer communications session encrypted via symmetric encryption.

In this way, asymmetric cryptography assists the cause of confidentiality. But these public keys are also part of a larger set of functions known as public key infrastructure, or PKI. PKI provides ways to be sure that any given public key is associated with a specific person or institution. A message encrypted with a public key thus confirms the identity of the sender, establishing authentication and non-repudiation.

Hash functions. Symmetric and asymmetric cryptographic algorithms both involve transforming plaintext into ciphertext and then back into plaintext. By contrast, a hash function is a one-way encryption algorithm: once you’ve encrypted your plaintext, you can’t ever recover it from the resulting ciphertext (referred to as a hash). Obviously, this too relies on one-way mathematical functions.

This might make hash functions seem like a somewhat pointless exercise. But the key to their usefulness is that, for any given hash function, no two plaintexts will produce the same hash. (Mathematically, this isn’t quite correct, but for any hash function actually in use, the chances of it happening are generally vanishingly small and can be safely ignored.)

This makes hashing algorithms a great tool for ensuring data integrity. For instance, a message can be sent along with its own hash. Upon receiving the message, you can run the same hashing algorithm on the message text; if the hash you produce is different from the one accompanying the message, you know the message has been modified in transit.

Hashing is also used to ensure the confidentiality of passwords. Storing passwords as plaintext is a big security no-no because that makes users prone to account and identity theft in the wake of data breaches (which sadly doesn’t stop big players from doing it). If instead you store a hashed version of a user’s password, hackers won’t be able to decrypt it and use it elsewhere even if they do manage to breach your defenses. When a legitimate user logs in with their password, you can just hash it and check against the hash you have on file.

Cryptography examples and techniques

There are numerous techniques and algorithms that implement each of the three types of encryption discussed above. They are generally quite complex and beyond the scope of this article; we’ve included links here where you can learn more about some of the most commonly used examples.

Secret key encryption:

Public key encryption:

Hash functions:

There is a wide range of hash functions with different specialized purposes. The list on Wikipedia is a good place to start.