Encryption is a technique in [communication] systems of applying an algorithmic transformation to two pieces of data (known as the plain text and the key) and producing a single piece of data (known as the cypher text) from which it is not easy to recover either the plain text or the key ''even if the algorithm used is known''. Reversing the process (getting the plain text from the cypher text, with the input of a suitable key) is known as decryption. There are two main categories of cryptographic systems: '''symmetric''' and '''asymmetric'''. In a symmetric cryptosystem, the same key is used to encypher as is used to decypher; obviously, letting an untrusted third-party find the key in such a scheme would be catastrophic, but symmetric systems have the advantage that they tend to offer reasonably good performance. The other main category is asymmetric cryptosystems where keys come in pairs, and anything that is encrypted with one key of the pair can be decrypted with the other key of the pair; this makes them fairly useful for situations involving identities, as one of the keys can be kept completely secret (it is usually called the ''private'' key) and the other key is made widely available and can be used by anyone (and is usually called the ''public'' key.) Digital signatures are essentially hashes of a text that have been encrypted by someone's private key. Checking the signature for validity is then a matter of computing the hash and testing that it equals the value that you get by decrypting the signature. For various reasons, governments are much happier about digital signatures than general cryptography, even though the underlying algorithms are often pretty much the same. Protocols like [SSH] and [SSL] work by using public-key (asymmetric) cryptography to establish a session-key (i.e. limited lifespan symmetric key) that is used for encrypting the main data streams. Using the private key rarely helps keep it secret, and using a session-key also speeds up comms (symmetric keys tend to be far quicker to handle.) Note that most modern cryptosystems also use compression; naive encryption of human languages otherwise leaves routes for attack based on frequency analysis. Note also that for most asymmetric encryption systems, encrypting your data with key A and then encrypting the result with key B is effectively equivalent to encrypting your data with key C, where key C has the property of being much less secure than either key A or key B. ** Resources ** Cryptography resources on the Wiki include: [Cryptkit]: A Tcl binding to the well-known Cryptlib [http://www.cs.auckland.ac.nz/~pgut001/cryptlib/] cryptography toolkit Simple substitution algorithms, such as [Caesar] and [rot13]: These are trivial to break, and there is a page devoted to [solving cryptograms]. Other (insecure) algorithms of historical interest, such as [vignere] (a misspelling of Vigenere) and [Matrix multiplication and encryption]: The page entitled [Encryption and decryption] has another implementation of Vigenere. A wide range of implementations of modern algorithms such as those used in [PGP]: One popular one is [blowfish], which appears in the ''trfcrypt'' module of [trf], in [tls], and in [security:encrypt and security:decrypt]. Also [tcllib] has an implementation of [RC4] Encrypted socket communications via [SSL]: Can be done with [tls] and with the ''trfcrypt'' module of [trf]. Cryptography for digital signatures and for detection of tampering of files: Popular algorithms include [sha1] and [md5], both of which are implemented in [trf] and [tcllib]. One-way hash functions: Widely used for purposes like hiding passwords. [Michael A. Cleverly] has posted an implementation of [crypt in pure Tcl] that is suitable for this purpose. [tcllib] provides [md5crypt] which creates MD5 hased passwords as used in more modern *nix systems. Also compatible with Apache's htpasswd command. [Huffman coding, part 2]: A step towards compressing encryption, if you don't transmit the map [Molebox encrypted Windows exe]: [NaCl - Networking and Cryptography library (pronounced "salt")]: [tcllib]: Includes pure-Tcl implementations of the [des], [aes], [blowfish] and [rc4] ciphers. It also has implementations of the [md4], [md5], [sha1], [sha2] and [ripemd] message digest algorithms. https://github.com/dancal/tcl_mcrypt%|%Tcl binding to libmcrypt.%|%: https://github.com/dancal/tcl_seed%|%Tcl binding to SEED encryption library.%|%: https://github.com/d5c5ceb0/CryptoVe%|%CryptoVe%|%: Tcl binding to MIRACL (Multiprecision Integer and Rational Arithmetic C Library) library. MIRACL is self-described as "a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography" ** Comparison of pure-Tcl cipher implementations ** The following table shows a comparison of the pure-Tcl cipher implementations from [tcllib] Each was used to encipher and decipher 16 bytes for a timing test. The first table gives aggregated times. In the second table we ignore the key scheduling phase and only time core data encryption. DES(0.8) DES 3DES AES-128 AES-192 AES-256 Blowfish RC4 2967 505 1039 874 1004 1184 38783 584 2769 409 865 2389 2856 3379 38735 572 - 275 609 703 - - 143 56 - 190 423 2246 - - 139 53 From this we can see that the [blowfish] cipher is the fastest block cipher but is crippled by the cost of generating the sub-keys. [AES] and [DES] both have cheap key scheduling. For [AES] decryption is significantly slower than encryption while for [DES] the reverse is true. [RC4] is currently fastest. Tests were done using a tclkit 8.4 executable. DES 0.8 is the one in tcllib 1.7 while the columns listed as DES and 3DES are using a sightly modified version of TclDES. Tests look something like: ====== time {rc4::rc4 -key $key $plaintext} 500 ====== or ====== time {aes::aes -mode ecb -dir encrypt -key $key $plaintext} 500 ====== <> Cryptography | Concept | Security