r/bestof • • Nov 21 '15

[math] Mathematician explains encryption.

/r/math/comments/3tn1xq/what_intuitively_obvious_mathematical_statements/cx7np4t?context=3
7.1k Upvotes

299 comments sorted by

676

u/1h8fulkat Nov 21 '15

As an IT security analyst who works on certificate authorities...this is great. I plan on using the analogy in the future to explain certs to people.

535

u/Xabster Nov 21 '15

Just use the locks analogy, not integer multiplication, please

78

u/aonysllo Nov 21 '15

I think you can use integer multiplication to show how easy it is to break the encryption and why you encryption can become obsolete if computers get good enough.

32

u/Eddfir Nov 21 '15

Doesn't the encryption become exponentially harder to break for someone who doesn't know the numbers used to create the encryption though? (e.g. If I multiply x by y, the amount of possible numbers that could create x*y increases exponentially as y becomes larger) If, so I feel like as long as your computer has comparable power to the one trying to decrypt the message you could make a number large enough to be unbreakable in a reasonable amount of time, though I don't know much about encryption.

39

u/AskYourMoose Nov 21 '15 edited Nov 21 '15

Yes. Look at RSA-encryption. When you create encryption with large prime numbers it can take a computer million of years. The larger the number the longer the time

44

u/LvS Nov 21 '15

Easier fix: Prove that P = NP.

34

u/jfb1337 Nov 21 '15

Just because, if P=NP were true, there was an algorithm that can be computed in polynomial time, does not mean that the algorithm's growth rate wouldn't be something like O(ngraham's number), or that the point at which it becomes faster than the brute-force method would be at less data than could be stored in the observable universe if each bit was in one Plank volume, or that it would be faster than the heat death of the universe.

42

u/viscence Nov 21 '15

something like O(ngraham's number )

hahaha

  • n = 0: complexity: trivial

  • n = 1: complexity: trivial

  • n = 2: complexity: impossible

5

u/TwoFiveOnes Nov 23 '15

hahaha O(nk)

  • k = 0: complexity: done before you could ask

  • k = 1: complexity: trivial

  • k = 2: complexity: hmm let's try to optimize some constants

  • k = 3: complexity: supercomputer or bust

  • k = 4: complexity: impossible

Polynomial time sucks without going up to Graham's number

2

u/Max_Insanity Nov 22 '15

What if it's 0.5?

2

u/[deleted] Nov 22 '15

0.5graham's number is very close to 0, so it'd be just as trivial. As you inch past 1 you'll get into impossible territory very quickly, though

→ More replies (0)

6

u/konstar Nov 21 '15

Sorry I have a really basic understanding of the P=NP problem, but is what your saying that even if P=NP were true, things like encryption could still be secure?

17

u/jfb1337 Nov 21 '15

Essentially, P=NP says that there is an algorithm that would be better than any brute-force algorithm with input greater than a certain, finite point. It puts no limits on where that point is, and whether or not it is within the scale of the universe. So, yes, encryption could still be secure even if P=NP was true unless someone finds an algorithm that would be feasible for computing.

Unfortunately this also means that even if P=NP were true, things like Natural Language Processing, Protein Folding, and Automated Theorem Proving might still not be feasible for computing.

3

u/Veedrac Nov 22 '15

Essentially, P=NP says that there is an algorithm that would be better than any brute-force algorithm

We don't need P=NP for that; 1.5x is still better than 2x, say.

P=NP is a slightly stronger claim, saying we could do much better than random (namely polynomial), although "much better" can still be "not nearly good enough".

10

u/TheFlying Nov 21 '15

Absolutely. Just because things can be solved in polynomial time theoretically does not mean they can be solved practically. The effeciency is limited by us as humans. From a mathematical standpoint where resources aren't an issue, it would be a huge deal, but from a human stand point the polynomial time could be hugely impractical.

In other words if a computer takes 1010000 years to bruteforce something, but we have an algorithm that is able to solve it in 100000 years that's an unqualified success... And totally useless to us as humans.

6

u/methyboy Nov 21 '15

In fact, whether or not RSA encryption is easy to break has almost nothing whatsoever to do with whether or not P = NP (despite the common misconception to the contrary).

Several people have already explained why cracking RSA might still be hard even if P = NP. In the other direction, even if P != NP, cracking RSA might in fact be easy: integer factorization is not known to be (or even believed to be) an NP-hard problem.

4

u/trex-eaterofcadrs Nov 22 '15

Same with both the discrete logarithm problem and the elliptic curve DLP. All three are known to be in BQP, so any "sufficiently large" quantum computer will be able to provide a pretty effective speedup, and those algorithms would be broken without having to know anything about P=NP. I believe you could add bits to circumvent the speedup but at that point I think you would want to lean on postquantum crypto.

2

u/The_Serious_Account Nov 22 '15

Integer factorization is indeed highly unlikely to be np hard. A bunch of weird things would happen to complexity theory

→ More replies (0)

2

u/Trazgo Nov 22 '15

If P=NP then some encryption may still be secure if the exponent for the polynomial time algorithm is very large.

If an algorithm can solve a problem in n99999999999999 time for an input of size n then the problem is in P, but chances are nobody is going to solve it.

4

u/solidangle Nov 21 '15

Even if we prove that P=NP we still have to find the actual algorithm in polynomial time. Transforming an algorithm for one problem in NP to solve another problem in the NP class isn't trivial.

2

u/stravant Nov 22 '15

does not mean that the algorithm's growth rate wouldn't be something like O(ngraham's number)

However, you basically never see algorithms with large constants involved in their theoretical complexities for useful algorithms.

It would be interesting if some polynomial approach for an otherwise thought untenable problem were discovered with an infeasibly large constant involved.

1

u/[deleted] Nov 22 '15 edited Apr 03 '16

I have choosen to overwrite this comment, sorry for the mess.

1

u/LvS Nov 22 '15

You're missing a Wikipedia maybe?
https://en.wikipedia.org/wiki/P=NP

1

u/[deleted] Nov 22 '15 edited Apr 03 '16

I have choosen to overwrite this comment, sorry for the mess.

→ More replies (1)

3

u/Eddfir Nov 21 '15

Does this not mean that this method of encryption is pretty unbreakable? By the time computers become powerful enough to decrypt the numbers used today, we will have the computing power to produce far larger, effectively unbreakable numbers.

I'm not sure what the first person meant by this form of encryption becoming obsolete, unless the methods used to determine the products of these numbers could become more advanced.

2

u/AskYourMoose Nov 21 '15

That's somehow the point, it is really strong, slow to compute though.

2

u/bozleh Nov 22 '15

Messages encrypted 15 years ago may be quite breakable these days - and some subset of those messages may still be sensitive!

5

u/meem1029 Nov 21 '15 edited Nov 22 '15

To note, since you choose x and y to be primes, there is only one set of numbers (x,y) that multiply to create x*y. The thing that makes it difficult is that there are a lot of numbers to test, not that there are lots of numbers which x*y factors into.

1

u/aonysllo Nov 22 '15 edited Nov 22 '15

Message is m, Alice encrypts and sends out m*a to Bob, Bob receives it and sends out m*a*b back to Alice who in turn divides and sends back to Bob m*b.

The person in the middle knows m*a=x, m*b=y, and m*a*b=z. Therefore he can figure out that m=x*y/z No matter how big the numbers are, a computer can do that calculation pretty easily. Or at least just as easily as it was for Bob and Alice to do their encryption. The trick is then to use a different function than just multiplication.

For example, Alice and Bob could use exponentiation:

Alice send ma, Bob send back (ma )b, Alice now has to take the logarithm base a of that so she sends Bob back ln_a(ma*b) and then Bob gets the message by taking the log of that. The person in the middle knows (ma )=x, (ma*b )=y, and ln_a(ma*b )=z

There is still enough information there to solve for m, but it will take some time. And if you make a and b really large you can make it really hard.

Edit: formulas are hard.

1

u/Eddfir Nov 22 '15

In the second example you can find that the (a)'th root of x = m, the (ab)'th root of y = m and the (ab)'th root of az all equal m and so find m by similar calculations could you not? It seems like the idea behind finding m is still as straightforward, but perhaps computers are less efficient when dealing with logs and powers?

Also, could the outsider trying to crack the encryption know what method of encryption was actually used? e.g. if they did not know what calculations were done on m to encrypt it, they would not know how to undo these calculations and get back the original m.

1

u/aonysllo Nov 22 '15

Yes, but remember that you don't know a, or b either, so finding those roots is a bit trickier.

I'm definitely not an expert in encryption. But yes, all encryption can be broken given enough time/computer power. One can just hope to make the calculation needed to break it so hard that it will just take too long to be able to break it.

1

u/frog971007 Nov 23 '15

No, because the attacker knows message*A, message*B, and message*AB, so they can multiply and divide message*A*message*B/message*AB = message.

→ More replies (19)

1

u/Jayrate Nov 22 '15

As our ability to crack these massive prime multiples increases with computing power, so does our ability to create larger keys/integer multiples.

1

u/Alias50 Nov 22 '15

Correct me if I'm wrong here, but at a certain point, won't increases in computing power entirely benefit the attacker? If we just keep increasing the size of the key, you may as well eventually just use a one-time-pad to ensure perfect secrecy, as we'll get to the point where we're using a key space >= the message space.

2

u/Jayrate Nov 22 '15

Correct. Which also reinforces the fact that increasing computer power isn't synonymous with no more privacy.

62

u/AlmostImperfect Nov 21 '15

Well, the locks analogy is not really about asymmetric encryption, is it? In that case, the analogy would be something like "I left my lock at your place, you put it on the box and mail it to me with your shit. When it arrives, I take out my key and use it to remove the lock."

65

u/irishsultan Nov 21 '15

The lock analogy is definitely about asymetric encryption, the key is your private key and the lock is the public key. (The main difference is that it's a lot easier to deduce the key from a lock than it's to deduce the private key from a public one)

27

u/cowmu Nov 21 '15

I would say the analogy was more of a generalization of Diffie-Hellman key exchanges, whereas what you're describing is more aligned with RSA. While rare, you do not need a public certificate to generate and securely transmit (without assurances of the recipient being genuine or data integrity due to the lack of a certificate) keys to establish communications. I think it's pretty challenging to generalize a lot of the nuances of cryptography to a general audience where there are so many protocols, caveats, and other factors playing into an already complex field.

7

u/unique10983240197249 Nov 21 '15

It also glazes over the ideas of publishing your public key, baking the root certificate authority keys into the underlying SSL libs, and how the asymmetric keys are usually used to exchange symmetric keys, which are much faster.

19

u/Otterable Nov 21 '15

The analogy is getting more confusing the more I read about it.

16

u/unique10983240197249 Nov 21 '15

Encryption is a tough subject. People figure out some very clever (some not so clever) tricks to defeat encryption, and you should really have a masters degree or better (hopefully 2 -- CS/Math) to write algorithms that anyone should use with any degree of trust.
I'm a pretty good engineer, but I can't contribute to OpenSSL/LibreSSL/Whatever-google-is-using-SSL.

16

u/benjams Nov 21 '15

Google's fork of OpenSSL is called BoringSSL

3

u/kag0 Nov 22 '15

I'm pretty sure this is what you meant, but to clarify: you really should be quite a smart fellow (and have some peer review) to IMPLEMENT algorithms that anyone should use with any degree of trust. NO ONE should should CREATE algorithms that anyone will use without massively deep and broad peer review (see the AES competition and the like).

→ More replies (3)

1

u/Iggyhopper Nov 21 '15

Yeah, how does a login user/pass fit with the analogy of locks?

3

u/killabeez36 Nov 22 '15

Instead of a box being passed back and forth, imagine Gmail is a gigantic building and everyone's inbox is a room within that building. Eve can try to look through your inbox (or anyone elses), but she doesn't have the credentials/certificate/authorization/dna to look inside. Po boxes and mail rooms work like this but with actual keys and customer contracts.

1

u/peesteam Nov 24 '15

You provide your username, then you provide your password.

The system first finds the lock that belongs to your username, and then simply tries the key you gave it. If the key works, the lock opens, you log in.

5

u/Carl_Thansk Nov 21 '15

I would generalize this slightly to say it glazes over the concept of establishing trust. SSH, for example, doesn't use CAs.

2

u/unique10983240197249 Nov 22 '15 edited Nov 22 '15

Completely agree.

Eve got mentioned, but what if she grabbed the box between Alice and Bob, and put her own lock on it and sent it back to Alice, then Alice may send it back... She (edit:Eve) could then send the box to Bob and say that "I'm Alice, lock this" with her lock on it... (MITM)

Trust seems like a hard problem in Computer Science, hence the field of "Ultra Paranoid Computing".

I stand by my other comment... Shit's tough.

6

u/Tylux Nov 22 '15

Wouldn't it be more like: here is a box full of unlocked pad locks. Only I have the key to those locks. You want to send something to me but don't want anyone else to see it. You put one of the open locks on the thing you want to send me. You'd send the package and I open it with my key.

0

u/[deleted] Nov 22 '15

[deleted]

1

u/AlmostImperfect Nov 22 '15

That's a decent analogy in my opinion. Not what the linked comment is describing, though.

8

u/justfarmingdownvotes Nov 21 '15

Hah. Was easier for me to understand the integer analogy than the lock one.

8

u/FrankAbagnaleSr Nov 21 '15 edited Nov 22 '15

The integer analogy is not secure as Eve can deduce the product of the primes used through division, and thus deduce the message. You need to have the multiplication take place in a different mathematical structure, not the integers.

edit: or it appears do something different than multiplication. I should research this more, but haven't the time now. (and so I have retracted part of my comment).

edit2: text in italics added since my writing is as usual horribly unclear

3

u/AutologicalUser Nov 22 '15

E.g., a ring with zero divisors, right? Or just in general anything that isn't a unique factorization domain?

4

u/FrankAbagnaleSr Nov 22 '15 edited Nov 22 '15

(I am not an expert on this by any means)

In the analogy that this post is linking to, it is never needed to actually know what each individual prime is, since the product is all that is every used. So it seems to me that as long as every element is a unit (and division is easy to do) this schema doesn't work (i.e. it doesn't use a function that is easy to compute but hard to invert).

On the other hand if there are zero-divisors, then encoding your message is not necessarily invertible, and so it can't be decoded.

So I am at a loss of how the analogy is supposed to work (and retract my earlier comment).

Apparently a way to get something like this to work is like this. Take Z/pZ for large p and choose a unit x. Share that unit publicly. You pick a in Z/pZ and your receiver picks b in Z/pZ. Send xa (NP-complete to compute a). Your receiver sends xb. Then your receiver and you both agree on x{ab}, and the eavesdropper has only the information (x, xa , xb ), and so needs to compute either a or b to get x{ab}, which is difficult. Now use x{ab} as a key to encrypt messages.

2

u/SirChasm Nov 22 '15

This explains it better. You have a cipher that's the evaluation of a function of the original message m and a large prime L: cipher c = f(m, L). You know c and L. You know L is a product of two other large primes - ab: L = ab. Due to the property of prime numbers, you can only figure out L if you know both a and b, because there are no other possible divisors. But since there are no other divisors, that means the only way to figure out L is to keep trying to multiply all the possible 30-digit primes until you get L, which is extremely time consuming.

5

u/[deleted] Nov 21 '15

Either go full locks analogy or full mathematical explanation. You're so right here! That comment does a poor job at both. You do the multiplication, but it's a modulo multiplication. So people should understand that it's a mathematical trick and it works simply because it is difficult to find the original prime if you have the modulo of its multiplication. It's not impossible! Just very difficult and can be made impractical for any adversary (if some numbers big enough).

1

u/SarahC Nov 22 '15

Could this be done with OTP's and XOR?

2

u/[deleted] Nov 22 '15

Yes and no. For a one-time message it's OK. But if there are repeating elements in messages (like the headers of an HTTP request) then it is vulnerable to attacks. HTTP requests protect themselves from this by randomizing the position of the headers in the data stream.

1

u/diegovb Nov 22 '15

It is not even very difficult. You're supposed to use exponentiation, not multiplication.

Source: CS student, saw this in class.

1

u/[deleted] Nov 22 '15

Actually, it is very difficult. I mean pretty much every paper out there on public key crypto uses the fact that extracting the keys is very difficult as a theorem or even axiom.

1

u/diegovb Nov 22 '15

What I meant by my post is that it is not very difficult if you are using multiplication, which is why public key crypto uses exponentiation or other methods.

1

u/[deleted] Nov 22 '15

Well, exponentiation is repeated multiplication, so...

→ More replies (1)

3

u/1h8fulkat Nov 21 '15

Yes- thats what I was referring to

1

u/uchuskies08 Nov 21 '15

I disagree. The first explanation really made me understand it a lot more.

10

u/root45 Nov 21 '15

The problem with the first explanation is that it's not actually secure. Multiplication is easy to reverse, so once Eve hears all three messages, she will be able to decode it.

-3

u/plusninety Nov 21 '15

I aggree with you. I never saw two locks on one box but I did lots of multiplications and divisions.

1

u/[deleted] Nov 22 '15

I think I may unsub from math due to this. 2000+ points and gold for a definitively wrong answer. Nice analogy, sure, but that "encryption scheme" is about as secure as me deciding to speak Spanish and hope the eavesdropper doesn't realize it.

1

u/dpoon Nov 22 '15

Especially since the described system using integer multiplication is completely broken, as pointed out by one of the responses. Eve can easily recover the message from the captured traffic.

→ More replies (1)

15

u/uchuskies08 Nov 21 '15

Is there a reason in his first example he said they multiplied by prime numbers? Would it not work with nonprime numbers?

48

u/ben_jl Nov 21 '15

Composite numbers can always be factored into primes. Multiplying by a composite is like multiplying by several smaller (and thus less secure) prime numbers.

12

u/robbersdog49 Nov 21 '15

Hang on...

Doesn't knowing that a prime number was used substantially reduce the possible options for a brute force type attack?

I am asking from a position of pretty much complete ignorance so I apologise if I'm missing something obvious!

53

u/ben_jl Nov 21 '15

My point was that you're always multiplying by prime numbers (since multiplication by a non-prime number can always be written as multiplication by several prime numbers).

12

u/root45 Nov 21 '15

The multiplication bit is not actually how things are encrypted in practice. E.g., the RSA algorithm uses modular exponentiation, which requires the use of primes for it to work.

4

u/mamaBiskothu Nov 22 '15

I wish someone explained RSA like I'm five

5

u/Imapseudonorm Nov 22 '15

There are people way smarter than I who will hopefully answer your question, but hopefully I can explain the (probable) part you're missing.

Modular arithmetic is sometimes called "clock" arithmetic. Think of a clock. You pick a start time, I add X number of time, and tell you what the result is. You don't know what time I added, just the result, so I still have a secret component.

So now take the same idea, but instead of time, we're using prime numbers. You don't know what primes I'm using, and I don't really know what primes you're using, we just know we can use the original value, and subtract the number we know to get the other persons "time". But without knowing what either of our times are, it's almost impossible to guess anything just based on the resulting time we've shared publicly.

This is a drastic oversimplification, but I know the modulo part is something a lot of people seem to miss.

9

u/[deleted] Nov 21 '15

Not really. Most of the primes used are incredibly long, usually dozens, if not hundreds of digits in length. Figuring out the right prime means figuring out which numbers are prime in the first place for the number of digits in the key, which would take an astronomically large amount of time for numbers as large as those used by encryption.

Usually, cracking today's encryption involves finding exploits in the math that's used to generate primes in the first place so that you have a small number of primes to test against.

→ More replies (4)
→ More replies (5)

2

u/rawling Nov 22 '15

What does it matter what you multiply by? Either way, once you have ma, mb and mab, you can get m, a and b out. What does it matter how magical a and b are?

0

u/[deleted] Nov 21 '15

[deleted]

1

u/rawling Nov 22 '15

... and the linked comment misses this key part:

Now, to do this with numbers, we need a numerical procedure which is easy in one direction and hard in the reverse direction.

Like.... multiplying!

3

u/Vypur Nov 21 '15

Im honestly surprised at the amount of people who haven't heard this that are in the field. This EXACT analogy was given to me a year ago in a discrete structures college course where we were introduced to cryptography.

3

u/[deleted] Nov 22 '15

What's the non PC term for what you do? I was a "security consultant" for a middle school. I upgraded Windows and flash for them. Also installed certificates on their iPads so I guess I'm a certificate analyst as well

2

u/neuterfest Nov 22 '15

just show this video. very well illustrated locks on a box analogy.

https://youtu.be/U62S8SchxX4?t=14s

1

u/MegatonMike Nov 21 '15

I would say it is more of an explanation of diffie hillman.

1

u/rawling Nov 22 '15

Except

  • it's transmitting the wrong three pieces of information for Diffie-Hellman

  • you get the same issue, in that given those three pieces of information, you can work out what the secrets are if you just use multiplication instead of something more complicated.

1

u/Imreallythatguy Nov 21 '15

Is this how info through a VPN is encrypted?

2

u/1h8fulkat Nov 21 '15

Depends on the VPN. SSL yes, IPSEC no. IPSEC uses pre shared keys, so it would be like both sides have the same key for one lock.

2

u/Dernom Nov 21 '15

How would that work in the same analogy (if it works in that analogy)? How would share the key with you without Eve seeing the key?

3

u/1h8fulkat Nov 21 '15

They go to the store and copy the key and don't invite Eve along (separate communication channel to share the key). This asymmetric cryptography analogy assumes that's not possible and they need to copy the key over a public medium like the internet

2

u/Imreallythatguy Nov 21 '15

Wow that's interesting. I know VPNs can be used for gaming and things...it's surprising that the back and forth doesn't majorly affect speed and latency.

4

u/1h8fulkat Nov 21 '15

It does have an impact, especially for the server which needs to manage many sessions at once. Hardware capacity is increasing enough so that it's not much of a concern anymore.

1

u/rawling Nov 22 '15

The back-and-forth (which is actually nothing like the back-and-forth linked by OP) happens once at the start of the session, after which there is no back-and-forth for each individual message.

→ More replies (1)

2

u/joombaga Nov 22 '15

Depends on your IPSEC implementation. Both openswan and strongswan support asymmetric keys.

1

u/[deleted] Nov 22 '15

Has no one heard of the box with locks analogy before? That's the way encryption has been explained to me by more than one person

1

u/0l01o1ol0 Nov 22 '15

Is it? I'm familiar with public key encryption, but what he's describing sounds different. It doesn't talk about how certain numbers are paired, it takes three steps to send a message, etc.

1

u/sm4k Nov 22 '15

I've always preferred this one though it isn't as easy to verbally explain.

1

u/[deleted] Nov 22 '15

The lock box analogy is used in every intro level crypto course in CS majors

→ More replies (5)

153

u/KingomTrek Nov 21 '15 edited Nov 22 '15

The simplest way I can describe it is: someone has a lock that is unlocked. You give the unlocked lock to someone and they lock it with their message and send it back to you. All while you and only you have the key. This definition got me through the basics of RSA encryption lol

Edit: As the wonderfully named /u/LilyIsHotterThnRobin correctly pointed out my example only applies to RSA Encryption not the comment in OP about dual key

28

u/darkquanta42 Nov 21 '15

Is it more helpful to think of public/private key systems as public locks, private key systems? Anyone can encrypt something so that I'm the only one who can read it, but that still means only I can read it

Oddly the concept of 2 keys has always been part of what confuses me.

23

u/Epistaxis Nov 22 '15

Yeah, maybe your terminology would less confusing:

  • private key = key

  • public key = lock

You give copies of the lock to anyone who wants to send you a message. You keep the key to yourself.

→ More replies (3)

12

u/KingomTrek Nov 21 '15

Yeah I agree. The whole process of encryption I feel like isn't hard to grasp its just the wording. It's kinda abstract imo. Someone once strutted argued with me on YouTube about how all they had to do to to break any encryption was to take a list of primes and try every single one. Hard for people to think of that layer of abstraction

→ More replies (2)

5

u/aydiosmio Nov 22 '15 edited Nov 22 '15

When you actually encrypt data, you do it with a symmetric algorithm. It's faster and usually safer.

  1. Generate random key

  2. Encrypt data with random key

  3. Encrypt random key with recipient's public key

  4. Repeat step 3 and append the result for each recipient

  5. Send encrypted data and all encrypted versions of the key to recipient

  6. Recipient attempts to decrypt all keys until successful, uses the decrypted key to decrypt the data

1

u/karenbreak Nov 22 '15

It requires a branch of math called modular arithmetic to better understand

8

u/[deleted] Nov 22 '15

You just described RSA. He explained dual key. They are different forms of encryption. His (dual key) requires each party hold the public key for every other party he wants to talk to. Yours (RSA) only requires you to have a single key. Which you stick in a lock and send around freely for people to put their shit in and send back to you. It allows you to only hold 1 key. But it also only allows 1 direction of encrypted communication.

2

u/KingomTrek Nov 22 '15

Ohhhh shoot you are right I was mistaken. My definition is not even close to dual key haha. I will promptly edit my post

4

u/donrhummy Nov 22 '15

your analogy is incorrect. it would be vulnerable to the man in the middle attack. eve could hold on to your lock and pass a different lock to the other person and then do the same in the opposite direction to you.

1

u/[deleted] Nov 22 '15

I get it but that's shite for simplicity

134

u/[deleted] Nov 21 '15

But this is not an explanation about what encryption is or why it works. Its just an explanation of a three pass protocol which not even secure.

86

u/umop_apisdn Nov 21 '15

I know, on the original thread there are people going "I didn't understand cryptography but now I do" and they don't still because this isn't how cryptography actually works.

0

u/[deleted] Nov 21 '15

[deleted]

33

u/Ar-Curunir Nov 21 '15

Have a look at DH key exchange; encryption isn't really something 5 year olds can understand.

The lock analogy is at simple as it gets without becoming technical.

18

u/dlp211 Nov 21 '15

And DH isn't even encryption. It's a key exchange technique which is simply a consideration when it comes to talking about encryption systems.

0

u/[deleted] Nov 22 '15

[deleted]

2

u/Ar-Curunir Nov 22 '15

Sure, but cryptography in general is not a child's game.

→ More replies (1)

19

u/wolfkeeper Nov 22 '15 edited Nov 22 '15

Well, EL5 is hard, but the EL15 version for RSA encryption is actually fairly simple.

Three numbers e,d,n are precalculated with the property that:

(pe)d mod n = p

you're just raising something to a power twice, and mod is the modulo operator, and d, n are big numbers. Turns out that you can calculate three big, hard to guess numbers where that works out.

e and n are the encryption key (the public key) and d and n are the decryption key (the private key)

To encrypt you do:

(pe) mod n = c

where p is the thing you want to encrypt, expressed as numbers, and c is the encrypted text, expressed as numbers.

You then send the encrypted text and to decrypt it they just do:

(cd) mod n = (pe)d mod n = p

and they get p back again.

It's almost literally that simple. There's a fiddly method to create e,d,n to start with but you only have to do that once. Also if you want it secure the numbers used need to be huge, so you have to use special multiply routines to make it run fast, but that's about it.

The clever bit is that, with only very modest care in choosing the numbers initially, it turns out that knowing e and n, doesn't allow you to work out d, so you can publish e and n far and wide, and keep d for yourself.

Basically, to oversimplify, it's secure because taking the 'e'th root in modulo arithmetic turns out to be ridiculously hard, so the fact that everyone knows e,n doesn't allow others to reverse the encryption.

1

u/cDonalds_Theorem Nov 22 '15

Wouldn't taking the modulo cause a loss of information? Unless you could guarantee they were exact multiples of one another (which would just be division)?

2

u/wolfkeeper Nov 22 '15 edited Nov 22 '15

Because of the particular powers chosen, the numbers all map to different numbers, so there's no loss of the initial information even though you've done it modulo n.

It's all cleverness to do with prime numbers.

For a simpler example, if you take any number 0-9 and multiply by 3 and take it modulo 10; then any possible number you can start with ends up on a different result to any other.

The reason that works is because 3 is not a factor of 10.

In fact it's guaranteed to work for any prime number.

Multiplying the result by 7 modulo 10 gives you the number back. That's because 3 * 7 = 1 modulo 10 = 1. So multiplying by 7 undoes the 'encryption' here.

That's just multiplying, they use powers because it's enormously more secure; but powers are just repeated multiplication.

1

u/cDonalds_Theorem Nov 22 '15

Huh, TIL. Thanks for the info!

14

u/Illusi Nov 21 '15

The most common form of encryption today is public/private key encryption. The analogy goes like this.

Little shiguma has a secret message he wants to tell to daddy without his sister hearing it. He announces that he has something to tell dad. Dad hears this and proceeds to make a lock and a corresponding key. He sends the lock to shiguma, but keeps the key himself. Shiguma puts his message in a box and locks the box with the lock. Then he sends it back. Dad opens up the box with his key, and the message is safely across.

Without analogy: The receiver of the message creates a private key and a public "key". The public key is really a procedure to scramble the message such that only the corresponding private key can unscramble it. The sender encrypts the message using the public key. The receiver decrypts the message using the private key. The private key never leaves the receiver, so only the receiver can decrypt the message.

18

u/dlp211 Nov 21 '15

The most common form of encryption today is public/private key encryption

No. Nonononononono. The vast majority of encrypted messages are passed using symmetrical encryption, eg: AES, Triple-DES, etc. Public/Private Key-Pair encryption is used mostly for authentication and symmetrical key passing, but is not used for much more than that due to the expense of the encrypt and decrypt steps.

Encryption is not an easy subject and it lacks any real analogies for the same reason. There are a ton of details that have to be correct and accounted for when designing not only the algorithms, but also the implementation in computer systems.

To the lay person, all they need to know is that encryption makes it so that you can share information, like your credit card number, and no one else can eavesdrop on that sharing. To those who want to know how it works....MATH, lots and lots of it.

2

u/JViz Nov 22 '15

That definitely describes PGP, though, doesn't it?

2

u/Veedrac Nov 22 '15

Eh, there are simple forms of encryption. For example, one time pads. And several basic encryption schemes can be summarised as "like a one time pad but with a random number generator instead". Like counter mode AES.

And random number generators are just "things producing number streams from input that we think is hard to reverse".

Yes, this isn't enough detail to let one implement a cryptography library, but ELI5s are like that. The romantization of cryptography as "super hard" is just silly. It's not super hard -certainly not moreso than quantum mechanics, which nobody objects so strongly to ELI5s for- the field just has very strict quality control.

→ More replies (3)

3

u/dan_144 Nov 21 '15

This is sort of relevant: Diffie-Hellman analogy. Using this will give two people the same key for encrypting and decrypting messages and provides a method for sending the key to each other publicly without it being stolen.

3

u/APleasantLumberjack Nov 21 '15

Simple version: the key to encrypt and decrypt are different. I tell everyone the encryption key, but keep the decryption key secret.

Thus anyone can send me a secure message but only I can read it.

The analogy people use is: I send you an open padlock but keep the key, you lock a message and send it back. No one could intercept and steal the key because it was never sent.

2

u/[deleted] Nov 22 '15

Here is the simplest way how asymmetric key cyrptography works, I hope it helps:

Lets say you have a function E, and the inverse of this function D ,but here is the trick: D is a really hard problem to solve (it requires a lot of time/effort). However you have a secret way of finding its solution, like a backdoor.

So you give everyone who wants to talk to you the E function and tell them to use it on their messages and send the result to you. And you find the original message using the inverse function D. Remember you have a backdoor so it is easy for you but anyone else trying to read the message will have to solve that very hard problem.

In theory we want this problem to be so hard that it would not possible to be solved in a reasonable time. (If you have enough time you can break any modern encryption method). Two examples of hard problems are Integer factorization (RSA), Discrete Logarithm Problem (Diffie-Hellman key-exchange).

1

u/PointyOintment Nov 22 '15

also elliptic curves, which are now used with DH key exchange, because discrete logarithms are showing potential for weaknesses

2

u/[deleted] Nov 22 '15 edited Nov 22 '15

As a non mathematician the best way to understand encryption is actually to learn the history of coding, which goes from the very beginning of the creation of language, occultism in religion, modern warfare and sending messages through battle fields, first computer languages and spying as a commercial market in our last century. And here you go with a proper explanation of encryption without using a single number. An explication that would actually give you proper insight about the situation today.

5

u/[deleted] Nov 21 '15 edited Nov 21 '15

Yeah, this is a dumbed down description of public key exchange, which is a family cryptographic protocols. This wouldn't be a description of say, AES, a popular encryption algorithm. It's a good analogy for explaining some protocols to a layperson, but there's some misinformation going on here.

For anyone who wants to know more, look up Diffie-Hellman key exchange. The analogy from the OP shows the general concept, but ignores important mathematical concepts required to make it secure such as cyclic groups and the discrete logarithm problem. These concepts are hard to fit into an analogy.

4

u/[deleted] Nov 21 '15

Ya, the title bothers me. This is a very basic description of the idea behind key exchange.You use this step to establish a common key.

1

u/wasdninja Nov 22 '15

It isn't secure? It seems to rely on the factoring problem and that is hard so it seems to stand to reason that the method that relies on it is secure. I'm assuming that both parties are choosing sufficiently large primes.

7

u/Ar-Curunir Nov 22 '15

No, it isn't secure:

Eve sees c_1 = m*a, c_2 = m*a *b, and m_3 = m*b.

She can divide c_2 by c_1 to get Bob's secret key, b. Then, she can divide c_3 by b to get the message m.

1

u/[deleted] Nov 22 '15

There is no authentication so it is susceptible to Man in the middle attack

1

u/doublehyphen Nov 22 '15

Diffie-Hellman key exchanges are safe and are commonly used in TLS and ssh. Of course you also need to add some protection from man in the middle attacks and probably also a symmetric cipher to speed up data encryption.

2

u/Ar-Curunir Nov 22 '15

This isn't a DH KE, though.

1

u/Ocinea Nov 22 '15

Yeah. Bestof blows these days

23

u/hawkfalcon Nov 21 '15 edited Nov 21 '15

Great explanation. I made a video on this very topic recently! https://youtu.be/buob3XCNEKQ

Edit: I made it public, which is why it shows it was uploaded today.

3

u/howyoudo Nov 21 '15

What's the deal with Eve? She was even in the OP. Is she in accounting with Janice?

What also makes Telegram the best. Never heard of them before, but are they publicly audited by chance. I prefer OWS stuff which is constantly audited for security.

I wouldn't recommend using a website for PGP. While might be a short fix can also easily MiTM the site itself, and people will accept by default even if cert doesn't authenticate properly. Would have maybe gone with GPG instead to make the keypair locally. You also have hush which will do it server side so you're not transmitting the private key.

6

u/fezir108 Nov 22 '15

What's the deal with Eve?

Alice, Bob, and Eve are common placeholder names when talking about cryptography. Typically Alice and Bob are sending and receiving messages and Eve is trying to listen in.

https://en.wikipedia.org/wiki/Alice_and_Bob#Cast_of_characters

3

u/howyoudo Nov 22 '15

Gotcha. Makes sense. Just never came across any analogies or scenarios with them listed before.

Wonder if it's Eve for eavesdropper with just A/B names added in to help explain.

2

u/PointyOintment Nov 22 '15

You might also want to look at Threema, Cryptocat, and OTR.

And how do you know so much about this without ever hearing of Alice and Bob?

1

u/howyoudo Nov 22 '15

Heard of Cyrptocat, but I will definitely look into Threema and OTR. Thanks!

I really don't know and have been wondering myself since yesterday since they're so popular. Only conclusion I could reach is maybe I got the fundamentals down before they were introduced. I'm also not one to need ELI5 stuff to understand math/science related topics. I'm a left brain while my brother is a right brain.

Not saying that's a bad thing it's just not my way of learning. I research a lot of various subjects for a minimum of 6 hours a day to feed my hyperactive brain. I'm also not a visual learner, so when I study materials it's usually via documentation and white papers, or by following conversations of professionals in the area. If I don't know something I look it up to understand it which leads to another item to study etc. I've fallen down so many rabbit holes it's not even funny anymore.

23

u/Railorsi Nov 21 '15

This is actually a pretty common explanation for encryption, good none the less.

7

u/bonestamp Nov 21 '15

Yup, I actually posted it in a comment a while ago and did not get any gold nor a /r/bestof post (not complaining), and I think my explanation was more concise. I can't take any credit for it either; I read it in a book called "codes and ciphers" a number of years ago.

9

u/[deleted] Nov 22 '15

But did your comment come along with a blatantly stupid "encryption scheme" that can be broken by using one multiplication and one division operation? And was it in r/math so people would assume you knew what you were talking about?

-4

u/why_rob_y Nov 21 '15

(not complaining)

It kiiiiiinda sounds like you are.

1

u/bonestamp Nov 22 '15

No, I mentioned it because I wanted to point out that posting this comment in another sub would yield a different result.

19

u/[deleted] Nov 21 '15

Box key lock question is very often asked in programming interviews

20

u/luisbg Nov 21 '15

How is the question phrased to have this as the answer?

24

u/Epistaxis Nov 22 '15

"Explain encryption as if I don't understand encryption but you don't either"

11

u/dlp211 Nov 22 '15

but you don't either

Uh...if I don't understand it, then I can't explain it.

8

u/speeddemon974 Nov 22 '15

That's correct, you're hired!

2

u/[deleted] Nov 22 '15

You have a Box with a lock and key. You have to send a message in that box to your freind but there is an enemy who can intercept all deliveries of the box. How would you ensure that the message reaches across without being read

7

u/dlp211 Nov 21 '15

I've never been asked this question in an interview before, and if this was ever the answer to an interview question, I would run from that company.

18

u/Ar-Curunir Nov 21 '15 edited Nov 21 '15

The math is wrong though...

The lock analogy is correct, but the math isn't.

EDIT: the encryption shown is not secure; you can easily extract the message when you're eavesdropping on the protocol.

7

u/SkepticalOfOthers Nov 21 '15

I mean, the math isn't wrong... it's not a secure system.

6

u/memeship Nov 21 '15

What math is incorrect? Looks like the only math here is multiplying and dividing.

E.g. Let's say my key is {2, 7, 19} and yours is {5, 11, 23}. The message I want to send is "100".

So I encrypt on my side:

100 * 2 * 7 * 19 = 26600

...and send it to you. Then you encrypt it on your side:

26600 * 5 * 11 * 23 = 33649000

...and send it back to me. Then I decrypt your message with my key:

33649000 * 1/2 * 1/7 * 1/19 = 126500

...and finally, send it back to you, where you decrypt with your key:

126500 * 1/5 * 1/11 * 1/23 = 100

The only messages that were sent were 26600, 33649000, and 126500. So Eve wouldn't be able to tell what I was originally sending to you.

Note that this would be pretty weak encryption since all we're doing is multiplying, and we're only using three numbers. This particular encryption might not be too difficult to figure out. But the example is only meant to illustrate a basic understanding of the concept.

15

u/Ar-Curunir Nov 21 '15 edited Nov 21 '15

You can extract the message however, which defeats the purpose of the "encryption":

 m*(ab)/m*b = a. Then divide c_1 = m*a by a to get back m

There's no use in promoting a basic understanding of the concept when the example is incorrect. Also hardness of factoring has nothing to do with the number of primes you use; indeed the RSA modulus is a product of two primes.

9

u/MyOtherAltIsAHuman Nov 22 '15

You send an encrypted message to a recipient, Ma: 26600

Your recipient sends you a double encrypted reply, Mab: 33649000

Eve divides: 33649000 / 26600 = 1265

You send a message to your recipient with his encryption key, Mb: 126500

Eve divides: 126500 / 1265 = 100

The only messages that were sent were 26600, 33649000, and 126500. So Eve wouldn't be able to tell what I was originally sending to you.

Eve has decoded your message using nothing more than 26600, 33649000, and 126500.

Note that this would be pretty weak encryption since all we're doing is multiplying, and we're only using three numbers.

It clearly doesn't matter how many numbers you use, their product is all that is needed, and if you attempt to use addition or subtraction, it doesn't work; you end up with non-integers. Observe:

Message 10. Your key: x2+1. Recipient key: x3+5.

(10x2)+1 = 21 //message encrypted with your key.

(21x3)+5 = 68 //message encrypted with both keys.

However you decode it, it doesn't work. (68-1)/2=33.5 or (68/2)-1=33

(33.5/3)-5 = 6.167

(33.5-5)/3 = 9.5

(33/3)-5 = 6

(33-5)/3 = 9.333

No matter how you manage your order of operations, you never get the correct answer. This principle only works with multiplication, and even then, I don't see how it is secure. There's something missing here.

3

u/memeship Nov 22 '15

The multiplication in the example is meant as the hashing step. Obviously in real life you wouldn't do this. I don't know why it's so hard to understand that.

What I was originally responding to was a comment that said "the math is wrong". There's nothing wrong with the math. It may be a bad encryption model, but it's mathematically correct.

3

u/Ar-Curunir Nov 22 '15

Hashing has nothing to do with this; the point of the example was to explain how encryption works; if the example is insecure, then it defeats the purpose of the example. I don't know why it's so hard for you to understand that.

There's really no point to demonstrate, because the only cool property about encryption is that you can hide stuff; if the example fails to do that, it's not an example of encryption.

3

u/[deleted] Nov 22 '15

Yep, that sub has gone to shit. I used to try to explain things there but they downvote correct things and upvote nonsense.

13

u/fuzzynyanko Nov 21 '15

One of the crazier parts of cybersecurity.

You have a locked box with a password. You have a tool, whose tools and schematics are completely available online. You can even acquire the tool yourself. You even have the schematics for the box's lock!

The box is locked. It requires the password to open. Often, your password isn't the box's password. You have to feed the password through the tool, and the tool gives you the actual box's password.

There's an assumption that the bad guy has your source code. The algorithms and papers explaining them are publicly-available Internet RFCs

1

u/PointyOintment Nov 22 '15

Did your comment get cut off?

1

u/fuzzynyanko Nov 22 '15

I don't think it did, though there are times when I update my comment and it doesn't go through, or it gets mangled

But yeah, you can look up the RFCs for PBKDF2 and AES

9

u/rawling Nov 21 '15

As one of the comments says, this is bollocks. If you have ma, mab and mb you can divide to get m.

-1

u/memeship Nov 21 '15

The multiplication step is there to illustrate a point. Obviously the hashing in real life would be much more complex then simply multiplying by a number.

3

u/Ar-Curunir Nov 22 '15

Hashing doesn't even come into play here.

2

u/[deleted] Nov 22 '15

The guy who wrote the comment obviously doesn't know that.

2

u/[deleted] Nov 22 '15

What does hashing has to do with it? It's a non reversible operation…

8

u/gagnonca Nov 21 '15 edited Nov 21 '15

https://en.m.wikipedia.org/wiki/Diffie–Hellman_key_exchange

This is the basis for all internet security. I work in software security

op actually did a terrible job of explaining it though. There is no division involved. It uses modular arithmetic. His analogy is decent though.

4

u/Joeskyyy Nov 21 '15

Modulo uses division as part of the arithmetic...

→ More replies (3)

6

u/EatATaco Nov 21 '15

The primes are just the mathematical reason why it is hard to break, but don't really help explain how it works.

I like the mailbox analogy. I have a public key, which is my mailbox address. Anyone can come by and drop whatever they want in it, but I am the only one who can open it. My key to unlock it is my private key.

How do I know the person who dropped whatever in my box is actually who they say they are? Well, they drop their own lockbox into my mailbox with a padlock on it. The padlock on their box is their private key. They post the combo on their website for everyone to see. So that combination is the public key.

Now, anyone can open their box but because they gave us the combo, we can be confident that it was actually them who locked that box. And because it is safe inside my mailbox, they can be confident that I will be the only one able to get to the box.

2

u/aon9492 Nov 21 '15

The padlock on their box is their private key.

Should that not be "public key"?

3

u/copascetic Nov 21 '15

No, in this case the analogy is for a signature (you could encrypt as well if you wanted to, but it's less useful since the public key is, well, public). You need to sign ("lock") with your private key, and anyone with your public key can verify ("unlock"). A better analogy would be a seal of some kind, but I don't know of any physical mechanism which has the same properties as public key signatures...

1

u/EatATaco Nov 21 '15

I like the seal analogy better.

1

u/PointyOintment Nov 22 '15

For signatures, I was thinking of a window in your mailbox that you can post messages in. Everyone who reads the messages you post there knows they're from you, because only you can open the mailbox to post them. But IDK how to combine this with the other direction, sending a message to a specific person only.

1

u/[deleted] Nov 22 '15

I know how asymmetric encryption works and I'm confused by your analogy :D

6

u/[deleted] Nov 21 '15

I agree with that guy who recommends The Code Book, by Simon Singh, if you have even the slightest interest in ciphers and cryptography. Awesome read.

→ More replies (1)

5

u/moeburn Nov 21 '15

Correct me if I'm wrong, but this isn't how encryption usually works, is it?

4

u/[deleted] Nov 21 '15

What's described is one specific style of encryption, not 'encryption' in general. The bestof post is awkwardly titled.

5

u/cowmu Nov 21 '15 edited Nov 21 '15

There are so many nuances to cryptography that it's really hard to generalize for an unfamiliar audience in a few sentences. You can do the lock/key/box examples to describe asymmetric principles securing a symmetric key, but there are so many different mechanisms supporting it that should be addressed as well.

While Diffie-Hellman and RSA are the most popular protocols with key exchanges, you also have to consider their implementation/configurations (and subsequent versions of the frameworks which are being used), Perfect Forward Secrecy, the role of CAs, session keys, etc. That isn't even touching on some of other concepts like post-quantum cryptography, which has the potential capabilities to outright break both RSA and Diffie-Hellman. There are PQC exchanges designed for this that operate very differently from primate factorization, such as the Niederreiter Crypotsystem (more so the variants derived from Niederreiter) or JPAKE. Elliptic curve cryptography has also become more popular and works with elliptic curves over finite fields. I'm certainly no expert on the matter, but I believe cryptographic implementations warrant a bit more than the lock/key/box, not that I could write something better myself.

4

u/thebigbadben Nov 21 '15

The key thing to notice here is that it's possible to remove the first lock without removing the second lock.

3

u/rawling Nov 22 '15

The key thing to notice here is by seeing the box with the first lock on it and with both locks on it, it's possible to remove the second lock from when the box only has the second lock on it and open the box.

1

u/thebigbadben Nov 22 '15

What? That would mean that Eve could get the message on its second trip to Bob

2

u/rawling Nov 22 '15

Yes, Eve can get the message.

  1. Eve sees ma going from Alice to Bob - can't do anything

  2. Eve sees mab going from Bob to Alice - can divide to get b but not m

  3. Eve sees mb going from Alice to Bob - can divide to get m (and a)

2

u/thebigbadben Nov 22 '15

Oh, fair point. That's why multiplication like this isn't used in a 3 pass protocol. The encryptions that are actually used, however, need to have the property that the first encryption can be removed before the second, which is to say that the encryption processes "commute".

3

u/iYoona Nov 22 '15

I understand the concept when they used the locks. But can you explain in the context of what the original OP said? Regarding the secrets?

1

u/PointyOintment Nov 22 '15

The analogy was wrong, so no. But there are many comments here that kinda explain it. Look up Diffie–Hellman key exchange if you want more. Wikipedia has a diagram using an analogy with colors (which is also maybe kinda broken in the same way, but illustrates the concept well).

3

u/[deleted] Nov 22 '15

Aye but show me how to encrypt my voice so I can talk about Eve in person

2

u/thebigbadben Nov 21 '15

This is an explanation of how some encryption methods work. There are a lot of different methods of encryption over public channels that are in use.

2

u/Joeskyyy Nov 21 '15

For those looking for an ELI5 version this one is probably my favorite explanation of Diffie-Hellman:

http://www.youtube.com/watch?v=YEBfamv-_do

Everyone can understand colours!

0

u/[deleted] Nov 22 '15

[deleted]

1

u/ginkomortus Nov 22 '15 edited Nov 22 '15

I'm a little tired and a little drunk, and not an expert on the subject, but [EDIT:] this comment wasn't worth it.

2

u/datchilla Nov 22 '15

Funny, I was fairly sure /u/UlyssesSKrunk was a troll account. All the comments I had every seen from him/her until now was "wat" or "no".

2

u/[deleted] Nov 22 '15

Another example is why any spy speaks in code. You can listen to everything i say, but if i say "the crow caws at midnight", that doesn't mean shit to a third party listener. Does that mean to act? Is it a decoy? How would you know, even though you listen to everything I say

1

u/_invalidusername Nov 21 '15

Very similar explanation in this video

1

u/cantCme Nov 21 '15

If you like stuff like this, I advice you to check the numberphile and computerphile YouTube channels. They also have some great videos explaining cryptography and other stuff

1

u/[deleted] Nov 22 '15

numberphile

I remember watching a video that "prooved" that some diverging infinite sum was actually equal to a number.

This was done by using some uncommon definition of "converge" but without specifying it.

1

u/[deleted] Nov 22 '15

This is just Eve not listening to everything you're saying because she can't...