Say I want to write an encryption algorithm to communicate between me and my friend for this private use. How is that bad?

E.g. I can take the word 'Hello' and encrypt it with a simple algorithm i.e. take each letter and multiply its value by 2 and add 13 so that it becomes completely unreadable.

Is writing a private encryption that stays between two people discouraged or not? What's wrong with it?

share|improve this question
15  
Schneier's law is something to the effect of anyone can create a cipher that they themselves cannot break. For example, your method listed in your question you say results in "completely unreadable" ciphertexts. Unfortunately it is fatally flawed. It would be easy for me to break. – mikeazo 13 hours ago
4  
    
Comments are not for extended discussion; this conversation has been moved to chat. – mikeazo 8 hours ago
    
Because there's no way to know if you got it wrong. – immibis 6 hours ago
    
I would add to the list @D.W. added via Software Engineering SE: Is reinventing the wheel bad?: Odds are, your "version" of crypto is: Incomplete, buggy, missing features, adds nothing new, missing documentation, etc. It can be a great tool for LEARNING - just like creating sorting algorithms... but in the real world, you shouldn't "reinvent the wheel" because your "wheel" is going to be lacking compared to tested and vetted versions. – WernerCD 2 hours ago

Your question, Mike Azo's comment, and your reply practically could not be a better example of Schneier's law in practice.

Anyone, from the most clueless amateur to the best cryptographer, can create an algorithm that he himself can't break.

You replied,

How can you break it if I send you this "QTCPIGXKUXTGG" ciphertext encrypted by a merely a simple algorithm which you have no idea about how it was encrypted?

Because even though we might not know exactly what your secret algorithm is, the first thing an attacker is going to reach for are common tools to attack substitution ciphers or polyalphabetic ciphers. Given even a few sentences of ciphertext is likely enough to fully recover every plaintext.

The fact that you don't know how to break it is irrelevant. It's trivial to create a cipher that you yourself can't break, but it's another thing entirely to create a cipher that others can't break. And the odds that you are capable of doing it when you're not aware of even the most basic attacks against ciphers hundreds of years old — not to mention modern concepts like indistinguishability under different attack models — puts you at an insurmountable disadvantage compared to ciphers designed by researchers with decades of experience in the field who are building off of modern notions of security and the discarded remains of thousands of failed ciphers that came before.

As an example, even if your cipher is somehow secure against a ciphertext-only attack (it's not), is it secure if I can trick you into encrypting a message for me? What if I can trick you into decrypting a message for me? What if I know part of or all of one of the messages you send? What if you encrypt multiple messages with the same key?

I'll leave you with another Schneier classic, Memo to the Amateur Cipher Designer:

A cryptographer friend tells the story of an amateur who kept bothering him with the cipher he invented. The cryptographer would break the cipher, the amateur would make a change to "fix" it, and the cryptographer would break it again. This exchange went on a few times until the cryptographer became fed up. When the amateur visited him to hear what the cryptographer thought, the cryptographer put three envelopes face down on the table. "In each of these envelopes is an attack against your cipher. Take one and read it. Don't come back until you've discovered the other two attacks." The amateur was never heard from again.

So here's your first envelope. Given a paragraph or two of ciphertext, your cipher will fail to language-based frequency analysis.

Let me know when you've figured out the other two attacks.

Edit: The comment about indistinguishability under different attack models is one reason why most "decipher this message crypto challenges" are completely bunk. They often simply give an attacker some ciphertext, ask them to decipher it, and declare victory when nobody produces the plaintext after some amount of time. Unfortunately that's not how crypto works in the real world; attackers have many more tricks up their sleeve in practice. They can trick computers into encrypting data of their choosing, they can trick computers into decrypting data of their choosing, and they can usually even do these things thousands, millions, or billions of times. Moxie's post shows how even the most terrible, horribly-designed, and obviously insecure ciphers can be effectively impervious when you restrict an attacker to a single ciphertext-only attack, which aren't representative of attackers' capabilities against ciphers as they're actually deployed in practice.

share|improve this answer
    
It's trivial to create a cipher that you yourself can't break: not if you are Bruce Schneier (or Chuck Norris). – mikeazo 12 hours ago
    
More evidence here. :) – mikeazo 12 hours ago
2  
The way we know a cipher is secure is by observing how it holds up to attacks from the entire cryptography community over years. You can't rely on a cryptographic system unless it has withstood that kind of scrutiny which requires that it be public and that it merit that level of scrutiny. You can develop whatever you want and play with it all you want, but you're a fool if you rely it until it has withstood that level of scrutiny -- it is just way too likely that a motivated opponent can break it. – David Schwartz 10 hours ago
    
Isn't the logical conclusion of this law that we can create encryption that nobody can break? As there must be a best cryptographer? – Cruncher 9 hours ago
1  
Only if you assume there's a strict ordering of cryptographers by that metric, which borders on the absurd. You can't strictly order tennis players or chess players on their ability to defeat one another. I think you'd have a hard time demonstrating that of cryptographers too. – Stephen Touset 8 hours ago

I actually think this is a really good question. The answer is because cryptography is a skill, and like any skill, it takes time to develop. Additionally, you will be pitting your (in)experience in the skill against the skills of those who would seek to break your algorithm.

This is the real reason why: It's not that you just shouldn't do it, period. It's that if you do write your own algorithms, you need to realize that it will take a long time before you create anything that is actually capable of securing your information against a dedicated adversary in the real world.

Cryptography is like sword fighting. You would not sharpen a bamboo stick, swing it around a few times, and then go challenge a pack of thugs to a fight. The reason why should be really obvious. Especially when the pack of thugs in question could be a 3-Letter entity such as DJB or other Nation State level Adversaries.

I say this as someone who is written too many crypto algorithms to count on both hands - I have written plenty of algorithms, but proposed and used none of them. Until you have something that 1. Is faster then AES or Salsa/ChaCha 2. Provably more secure then AES or Salsa/ChaCha, why should you propose or use the algorithm in question?

Lastly, you will likely enjoy studying information theory. You will come to understand that keeping the algorithm secret is not efficient because the algorithm itself has a minimum number of bits required to represent it. These bits (the algorithm) simply become the key. It is well established that it is simply better to concentrate your secrecy into a proper small key with a public algorithm. If your key becomes compromised, you simply change the key. If the algorithm is the key, well, you'd need a whole new algorithm.

tl;dr

I disagree that you should not write your own algorithms, it's that you need to have a good explicit reason for using/proposing your own algorithms. I personally would encourage you to write your own, as it will teach you to understand what does and what does not work and why. Doing so will help you to understand various sorts of mathematics and information theory (basically all of the math that I know I learned because/for cryptography).

share|improve this answer
5  
+1 for pointing out the important distinction between building your own algorithms (and breaking them!) and actually using them in practice. Build away to your heart's content, but don't be naïve enough to use it for anything meaningful, and please don't be the kind of wildly irresponsible person that publishes it alongside with a fancy-looking webpage that encourages other people to use it. – Stephen Touset 10 hours ago
1  
And another +1 for mentioning the Kolmogorov Complexity explanation of Kerckhoffs' Principle. Great point. – outis nihil 9 hours ago
3  
An excellent real-life example of making up an encryption algorithm is Solitaire, an encryption algortihm developed by Bruce Schneier for Neil Stephenson's book Cryptonomicon. He, being an expert in the field, designed it to be more secure than the average pen and paper cypher, but explicitly made no guarantees. It took several years of the public poking at it before someone discovered issues with the symmetry of the Jokers which leaked a bit of key data every now and then. Even Bruce himself had no reason to assume the algorithm was flawed until long after the book was in print. – Cort Ammon 9 hours ago
    
@StephenTouset: Especially in embedded systems, there is sometimes a need to have an algorithm be extremely cheap, while guarding against casual "attacks" [e.g. ASCII dumps]. A less-secure approach that takes four CPU cycles per byte might be preferable to a more-secure one that takes five, if it's unlikely that an adversary would have the time or inclination to break the scheme. – supercat 8 hours ago
    
I'm not entirely sure what that has to do with anything I said in my comment. That said, highly-optimized versions of ChaCha20 are four cycles per byte or even faster on modern hardware. You can even use reduced-round versions (ChaCha12 or ChaCha8) that squeeze in at under 2 cycles per byte. There's no excuse at this point for rolling your own crypto to use in a production device. – Stephen Touset 8 hours ago

In addition to the great answers on cipher complexity, I think it should be mentioned that the security engineering of the code that implements and utilizes ciphers - things like key exchange, key selection, and the generation of entropy - is very hard as well. Ross Anderson has a terrific book on Security Engineering, but an earlier essay of his (from 1993!) introduces some of the main points specific to cryptography (using old ATM security models as his case study), "Why Cryptosystems Fail" (1st Conf.- Computer and Comm. Security ’93, http://web.archive.org/web/20160125024658/http://www.cl.cam.ac.uk/~rja14/wcf.html).

share|improve this answer

It's discouraged because (A) it's statistically unlikely that a beginner comes up with a strong cipher and (B) lacking a working knowledge of cryptanalytic techniques, a beginner won't know that their cipher is vulnerable.

With most engineering problems outside of security, it will be obvious when things aren't working. If your video codec doesn't work you'll have strange green lines all over the display; if your stairs sensor doesn't work, the robot falls down the stairs, etc. But if your cipher is cryptographically vulnerable, you will still be able to encrypt and decrypt messages just fine. The only problem will be that people without the key can also decrypt the messages, and they won't necessarily be eager to inform you of this.

share|improve this answer

It is discouraged, for all the good reasons the people already answered you (so I won't repeat).

There is a twist, however (which is the point of this answer) - no matter how weak your cipher is (and it IS weak), it has two advantages going for it:

  • it is more secure than plaintext that you had before (even if only by slight margin, as you're not experienced in crypto).

and (this one is going to be controversial)

  • it might actually give you more of a chance of not being spied upon if you're not already interesting target for NSA or some other agency. (Now before you people downvote me to hell with "security though obscurity doesn't work" please allow me to explain :)

As mentioned above, if you're specifically targeted, using toy-cipher won't help you at all and you're practically as unprotected as when you were using unencrypted communications (or even slightly worse, as you might take more risk talking when believing you're protected).

However, beside (or one might argue: before) security of the cipher itself, and security of its implementation (those are two very different things, remember Debian GNU/Linux OpenSSL fiasco for example) there is one other key factor in determining if your communication is going to be de-privatized. And that is, "will anyone try"? And someone will try if any of the 3 things are true:

  1. you're interesting target yourself (for example: top politician, financial access / banks, celebrity status, have access to rare information, etc)
  2. you're perhaps not interesting yourself, but there is a lot of "you" using same security method. In other words: popularity. Sure, facebook does not contain much of top secret data, but having a way to access ANYONEs facebook account is going to be very good incentive for hackers to try to crack its protections .
  3. bad luck (eg. some hacker is bored and just happen to take a pick on your site, transforming it to point 1. above)

Now, sure TLS1.3+AES256-GCM/SHA512 is great thing today. Nobody can spy on you (except NSA and friends, but if you made enemy of them, you're done already). But there is enormous amount of people using it, and thus it becomes enormously profitable to crack it. So it will happen.

Not today, not in 5 years perhaps, but in 50 years random script kiddie would probably be able to decrypt your communications (as you didn't use PFS, doh!) with a simple click.

However, your toy-crypto chat, used in the whole world only by you and your friend to talk about slightly embarrassing fetishes, will likely remain hidden from everyone but legitimate parties for all eternity. Simply because nobody cared enough to give it minimum of effort needed to crack it, and it wasn't popular enough that is was decrypted by default by some PRISM-like mass surveillance.

But the other answers had it correct; best practice for continued secret communications currently is: "a) don't make enemies of various TLA government agencies. b) use secure popular ciphers implemented by competent programmers. c) keep upgrading both ciphers and implementations until at least the day you die" - although it is usually (with perilous results) often shortened just to half of point (b) "use secure popular ciphers".

But I'm wondering if in the long run we wouldn't all be much better if we had billions of obscure and insecure ciphers each used only by few people; as apposed to few supposedly uncrackable ones that everybody uses (but which are secretly flawed - which is known only by 1984-ish goverments and other murky elements.

As (anecdotal) "evidence", every month I help fix dozens of broken wordpress/joomla/etc sites which were "sooo secure" just a few months/years ago. But strangely enough, every now and then I stumble upon properly written (eg. verifies input :) old perl or even shell scripts, using insecure RC2 or even just hackish XOR, which still stand strong after decades. Just because there were different (and not popular) and nobody cared enough to spend time to crack them.

As your biggest problem nowdays is probably not that you will get targeted, but instead that some automated bot will exploit some hole in popular piece of software which you didn't patch quick enough. As there is limited amount of crypto-crackers, and there are most of the time chasing bigger cat than you. So you'd most likely become low-priority ticket and thus fade into oblivion.

share|improve this answer

I think much of these answers are really derivatives of a much greater and simpler understanding of cryptography.

Besides a one time pad, all cryptography is based on is mathematics and probability.

It's possible someone with no knowledge of anything could break a huge RSA key first cpu cycle, but what is the likelihood? Well we know it, and it's not too good even if an extremely powerful super computer so we trust it. What's the likelihood someone could break the encryption you described? Much much higher.

I think you should negate your question and ask really: Why should I write my own encryption algorithms?

I really don't see a point unless you are developing an algorithm which has some sort of benefit in regards to security or performance.

share|improve this answer
    
Hi @Nick, Welcome to Crypto.SE. We are glad you took time to answer here. However you need to make sure that you are providing meaningful additions to the already present answers. I am sorry to inform you that as is yours is opinion based (cf 1st, 4th and 5th paragraphs), subjective and extremely vague (cf your 3rd paragraph) . – Biv 6 hours ago
    
I would suggest you to have a look at the help center: How do I write a good answer? – Biv 6 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.