I am guessing this probably has a really long answer, so feel free to give a little explanation, with a link to a helpful article, tutorial or w.e

How can I encrypt a file without using one of those tools like FileValut, Knox, Disk Utility, openssl, GnuPG, etc? Like actually do that manually... I don't necessarily want to do it, but I want to understand how it works...


You can't actually encrypt a file without either using a tool (like the ones you mention), writing your own or doing it by hand (with paper and pencil).

Strong Crypto by hand: Solitare (Pontifex)

An interesting way to start understanding cryptography is to get a deck of playing cards and use Bruce Schneier's "Solitare" encryption method as used in Neal Stevenson in his book Cryptonomicon.

Other online resources

A good free book that starts with the Caesar Cipher is ftp://ftp.pgpi.org/pub/pgp/6.5/docs/english/IntroToCrypto.pdf

More fun stuff to try the Caesar Cipher http://www.purdue.edu/discoverypark/gk12/downloads/Cryptography.pdf

A rather mathematical approach to the subject http://math.scu.edu/~eschaefe/crylec.pdf


Some great books:

  • The Code Book by Simon Singh
  • Cryptanalysis by Gaines

Update: Here's an extract from Wikipedia:

Weak Crypto by hand: Caesar Cipher

The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places (the shift parameter, here 3, is used as the key):


When encrypting, a person looks up each letter of the message in the "plain" line and writes down the corresponding letter in the "cipher" line. Deciphering is done in reverse.

Plaintext:  the quick brown fox jumps over the lazy dog

The encryption can also be represented using modular arithmetic by first transforming the letters into numbers, according to the scheme, A = 0, B = 1,..., Z = 25.1 Encryption of a letter x by a shift n can be described mathematically as

enter image description here

Decryption is performed similarly,

enter image description here

(There are different definitions for the modulo operation. In the above, the result is in the range 0...25. I.e., if x+n or x-n are not in the range 0...25, we have to subtract or add 26.) The replacement remains the same throughout the message, so the cipher is classed as a type of monoalphabetic substitution, as opposed to polyalphabetic substitution.

  • Oh, I was not clear enough in my question... before I can learn the various methods for encrypting things, How do I actually get the binary data of a file? I am fairly experienced in a few languages, but I cannot find a method or command or attribute to return the data.. how do I do that? – FALL3N Jan 10 '12 at 23:29
  • 1
    @FALL3N: To learn the basics, start with plain text. To encrypt a binary file, encryption programs just read the byte-data of the file (in binary mode on Windows). If you wanted to hand-encrypt a binary file (a strange thing to do) you might serialise it to ASCII using something like base64 encoding or whatever is appropriate for the specific algorithm you are using. I recommend you buy and read the Gaines book. – RedGrittyBrick Jan 11 '12 at 10:28
  • @FALL3N: I have updated my answer with something you can use to encrypt and decrypt a text message (after removing all white space and non-alpha characters). It isn't secure but doing it will give you an idea of the basic aspects of private-key cryptography. – RedGrittyBrick Jan 11 '12 at 10:37

Encryption can be either very complicated or very simple. All of the tried and trusted tools you've listed have complex encryption schemes (which are, by design, very hard to break). However, at the other end of the spectrum it's very trivial to "encrypt" a file (provided of course you don't want it to be secure).

So, let's imagine you have a file you'd like to encrypt. There's no use giving it to someone else in it's encrypted format, so what we do is we use a thing called a key which allows the algorithm to run in reverse and restore the data to it's original state.

A very simple example of this is XOR encryption (XOR is a logic operator, "exclusive or"). It's trivial to implement a very simple program in something like C to encrypt a given file based on a key. See here for an explanation of how all of this fits together and a tutorial: http://www.cprogramming.com/tutorial/xor.html

You can also study the various algorithms used in the tools, however note they are not as simple as merely XORing the bits. The principle is the same, though.

So to summarise: have file -> define key -> run file through some algorithm to encrypt based upon the key -> encrypted file out.

Hope that helps.

  • Yep, one simple but fairly secure encryption scheme is a "one time pad", where you XOR your data with some other long data value (which is essentially a very long key). The data value can be, eg, bits from a JPEG file or some such (though it's best if the bits of the key are first mixed up a bit with a sort of hash algorithm). – Daniel R Hicks Jan 9 '12 at 1:06
  • I assume that this will stop patterns occuring in the output file, which of course makes it harder to bust. You could also compress the file using something like zip as an added layer of complexity. – NOP Jan 9 '12 at 2:03
  • 1
    Correct. If you used an un-hashed file for a one time pad there would inevitably be some bit patterns (strings of zeros or blanks) that allowed unencrypted text to sneak through. But it doesn't take much to "mix up" the data a bit and prevent this. (Used to be that the big problem with a one time pad was that the huge key file was so difficult to separately "transmit" between endpoints, but now those on both ends just need to know to pull the same file off the internet. The "shared secret" is which file.) – Daniel R Hicks Jan 9 '12 at 2:50
  • 1
    (But of course there are other more numerical algorithms that are quite secure when properly implemented.) – Daniel R Hicks Jan 9 '12 at 2:52
  • oh, thanks I'll read the tutorial. Sorry, I was very unclear in my question. I can see making an effective encryption will be a difficult task in itself, but I am decent at a few languages but I cannot figure out how to get the binary code, or any other code representing the file in those languages,, except for like text files, cuz I can just read them but I don't think that's the real way... is there a method or attribute to read or command that will get the binary data of a file so that I can encrypt it? – FALL3N Jan 10 '12 at 23:27

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