# Encryption and C++

**URL:** <https://boards.straightdope.com/t/encryption-and-c/96955>\
**Category:** Factual Questions\
**Created:** [December 5, 2001, 2:41am UTC](https://boards.straightdope.com/t/encryption-and-c/96955 "2001-12-05T02:41:10Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![JonF](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@JonF](https://boards.straightdope.com/u/JonF)\
**Post date:** [December 6, 2001, 5:26pm UTC](https://boards.straightdope.com/t/encryption-and-c/96955/21 "2001-12-06T17:26:16Z")

</div>

> [@](#):
>
> \*Originally posted by gazpacho \*
> 
> > [@](#):
> >
> > \*Originally posted by JonF \*
> > 
> > > [@](#):
> > >
> > > \*Originally posted by Lost In Reality \*  
> > > I am trying to make my own orignal code, I don’t trust anyone elses.
> > 
> > Bad attitude. I’m not saying you should trust someone else’s code without evaluation, but trusting anyone’s (including your own) code without evaluation and attack by an independent party or parties is not a good idea.
> 
> You are doomed. How do you know that you can trust the compiler that you will compile the code with?

Excactly. Read Secrets and Lies.

---

<div class="post-metadata">

**Author:** ![JonF](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@JonF](https://boards.straightdope.com/u/JonF)\
**Post date:** [December 6, 2001, 5:34pm UTC](https://boards.straightdope.com/t/encryption-and-c/96955/22 "2001-12-06T17:34:50Z")

</div>

> [@](#):
>
> \*Originally posted by scotth \*  
> I probably should have qualified my statement though. There are several different encryption environments to deal with.
> 
> 1. One to One message passing. Your encryption engine and keys are not available for analysis to anyone trying to break your code. This makes your job much easier.

However, if you are trying to implement a real-world security system, ensuring that “your encryption engine and keys are not available for analysis” is far, far tougher than figuring out an engine and keys. In fact, it’s _so_ tough that professional cryptographers always assume that the attacker _has_ the encryption engine, and have done so for a few hundred years.

> [@](#):
>
> 1. Commercial encryption with out public keys. Much tougher, as potential codebreakers get to see the guts of the encryption engine.
> 2. Commercial with public keys. By far the toughest to do mathmatically.

You missed a category, which is one of the most common:

1. Symmetric (private key) encryption with public-key encryption and protocol (e.g. Diffie-Hellman) for key transmission.

This is what [PGP](http://www.pgp.com) and many other products do. Symmetric systems are desirable because they’re typically much faster than public key algorithms.

---

<div class="post-metadata">

**Author:** ![Green\_Eyed\_Stranger](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@Green\_Eyed\_Stranger](https://boards.straightdope.com/u/Green_Eyed_Stranger)\
**Post date:** [December 6, 2001, 8:23pm UTC](https://boards.straightdope.com/t/encryption-and-c/96955/23 "2001-12-06T20:23:49Z")

</div>

> [@](#):
>
> Originally by **gazpacho**  
> You are doomed. How do you know that you can trust the compiler that you will compile the code with?

[You can’t](http://www.acm.org/classics/sep95)

Most everything else has been pretty well covered.

GES

---

<div class="post-metadata">

**Author:** ![Sam\_Stone](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@Sam\_Stone](https://boards.straightdope.com/u/Sam_Stone)\
**Post date:** [December 7, 2001, 2:46am UTC](https://boards.straightdope.com/t/encryption-and-c/96955/24 "2001-12-07T02:46:36Z")

</div>

For a high-school level project, I would suggest that you write a simple Feistel cipher. The Tiny Encryption Algorithm I posted above is a Feistel cipher. Read up on them, and you should be able to implement your own design fairly easily. It won’t be secure, but at least it will be an implementation of a real-world cipher.

The tricky part of a Feistel cipher is coming up with a transform function that is secure. If you don’t really care about that, just use the XOR trick listed above in your transform function.

Feistel ciphers are good for school projects because the basic concept is simple, and you can write some pretty simple-yet-cool algorithms to make it work.

[Previous page](https://boards.straightdope.com/t/encryption-and-c/96955.md?page=1)
