Teen Programmers Unite  


Return to forum top


Posted by Cortez [send private reply] at August 04, 2002, 11:17:59 AM

Can someone post a encrytpting program? (C or basic). I tried to find some stuff over net but all they have is very complex structures.

Posted by Psion [send private reply] at August 04, 2002, 12:38:30 PM

You need what you would probably call a very complex structure to have encryption that is not easy to break.

Posted by FatalDragon [send private reply] at August 04, 2002, 04:59:34 PM

Did you look for the PGP source code? (It's probly complex though...)

Posted by gian [send private reply] at August 04, 2002, 05:09:31 PM

A book like "Applied Cryptography" has C sourcecode for some of the simpler encryption algorithms.

Posted by Cortez [send private reply] at August 05, 2002, 03:50:04 AM

I meant, a postable code guys.

Posted by Psion [send private reply] at August 05, 2002, 07:48:40 AM

Anything short enough to post will be for really bad, easy to break "cryptography." Sorry!

Posted by gian [send private reply] at August 05, 2002, 11:27:49 PM

Cortez, try and get your hands on that book. It is excellent.

Posted by shroomrefic29 [send private reply] at August 11, 2002, 05:54:04 AM

try the "XOR" encryption algorithim, search it up in google.com

basically it works like this, it takes 2 streams of bits, one bieng the key, and the other being the plaintext. And XOR's it. XOR works like this:

take 2 bits, 1 and 0, if you "XOR" it: 1 ^ 0 : 1,

XOR outputs a 0, if the 2 bits are the same: 1 ^ 1 : 0, while 2 differing bits output a 1, 1 ^ 0 : 1,

So we have a key and plaintext:

Key : 1 0 0 1 1 0 1 0 0 1
Plain text : 0 1 1 1 0 1 0 1 0 1
1 1 1 0 1 1 1 1 0 0 (result after XOR)

in C-style language (not complete code listing!)


int Plaintext = 'c';
int Key = 'f';
int ciphertext;

Plaintext ^ Key = ciphertext; // Voila', Encryption!


Yes, ^ is the XOR operator in C/C++. This sort of encryption should not be used to protect commercial, or critical data, it easy to retrieve the plaintext. Other methods of strengthening the cipher is to generate random data from the key itself and expand it to a large amount, 64kb * 16 is considered a safe number, kilobits that is. Probably by using chaotic theory, you can obtain sufficient results, and the "random waveforms" it creates are completely random (Certain Lorenz Chaos Functions of sorts).

Other ideas for encryption algorithms include Substitution, and Permutation. These are simple "child-hood" ciphers when the word Hello becomes eholl, thats Permutation, and substitution is replacing a certain value with another, for example. Subtitution Modulo 26, basically "wraps around" the alphabet like so:


So Hello becomes : URYYO. H = U, E = R, L = Y, etc...

These are different methods of "encryption" if you use these 3 methods you can ahchieve a quasi-strong encryption algorithm.

Using all 3 in sync is the hard part. But you must remember, most succesful cryptography attacks, attack the implemention of the system, not the actual mathematical algorithm, such as examining RAM, for stored buffers, Non-random-ness in the Random Number Generator. Searching File Caches for keys, etc... etc...

Just some ideas to throw at you. Let me just throw in a disclaimer, I am not a cryptographer by trade, maybe as a hobby yes, but not as a professional. Use my tutorials as a "Rough" outline. This is just to provide certain key issues with cryptography rather hastidly put-together, with extremely horrible grammar. It seems my caffeine reserves have been depleted.

A question for PSION: should I write a more detailed, and cleaner tutorial on cryptography?

Posted by Psion [send private reply] at August 11, 2002, 09:01:06 AM

I don't think that's necessary. You'd have to use "complex structures" to get anything useful, and Cortez has already ruled those out. =)

Posted by RedX [send private reply] at August 11, 2002, 03:33:31 PM

Or build list for each word type (subject, verbe,...) with one word for each letter of the alphabet. Then replace each letter of the message by a word of these lists in a grammatical correct way. (subject, verbe, adjective, whateverAlTheseOtherWordsAreCalled) and, ofcourse, with the necessary spaces and dots.
It would be hell of a job to get the lists tuned.

Posted by shroomrefic29 [send private reply] at August 11, 2002, 04:27:23 PM

Another usefull tool for XOR. XOR alternates between value such as:

value1 ^ value2 = mask

so then

value1 ^ mask = value2

and then

value2 ^ mask = value1

And the "mask" that it creates, points out the DIFFERENCES in the bit streams, so then you can effectively make a "Patcher" of sorts.

So take for example you have an executable, it was your first release. After a month you make changes to the executable, but dont want to redistribute and entirely new executable. You can simply XOR the first executable and the second one together and you get a mask of the 2, and the DIFFERENCES in them. So then you you have a flagged bit mask of the areas your suppose to be updating. Easy as that. But of course the method of actually patching is a bit harder, but you get my point. I know this has absolutely NOTHING to do with this thread, but just wanted to point out the usefullnes of the thing we call XOR

Posted by shroomrefic29 [send private reply] at August 15, 2002, 09:10:36 AM

Ammendment: XORING produces a 1, as the result of two subsequent bits that are the same, and produces a 0, when the two subsequents bits are different, sorry for the mistake, here's a truth table to look at:

a | b | XORED
1 | 0 | 0
1 | 1 | 1
0 | 0 | 0
0 | 1 | 0

Posted by RedX [send private reply] at August 15, 2002, 10:08:30 AM

The truth table for XOR is:
0 xor 0 = 0
1 xor 0 = 1
1 xor 1 = 0
0 xor 1 = 1

If exactly one of the inputs is high then the output is high else the output is low.

The table you gave is for AND

Posted by whizkide [send private reply] at August 16, 2002, 05:09:04 PM

i learnt this matrix encoding method in elementary school maths.Hey dont crucify me yet.It converts everything to an int and multiplies a matrix ofnumbers supplied by the user and then reconverts back to character . If u really need a simple hack, u could try that.

Posted by shroomrefic29 [send private reply] at August 17, 2002, 09:07:43 PM

Thanks RedX i was quite confused for some time. :)

You must be logged in to post messages and see which you have already read.

Log on
Save for later automatic logon

Register as a new user
Copyright TPU 2002. See the Credits and About TPU for more information.