|
Javascript
DES Implemenation
This is an implementation of DES (the Data Encryption
Standard), an encryption algorithm which works
on bits. It supports Electronic Codebook (ECB)
and Cipher Block Chaining (CBC)
and also includes Triple DES. This page describes
how to it and provides the source code. The
explanation page shows
how the bit manipulations work, and gives links
to some general descriptions of DES.
Usage
des (string key, string message, boolean
encrypt, [integer mode, string iv])
The des
function accepts an 8 character string as the
key (this is 64 bits, but the algorithm only
uses 56) for normal DES or a 24 character
string for triple DES, a message string, a boolean
to say whether the data should be encrypted
or decrypted, an optional mode (0 for ECB and
1 for CBC, ECB is the default), and an optional
8 character string input vector (not used in
ECB mode). It returns the cipher text as a string.
Here are several
examples showing how it can be used:
//encrypt using
single DES (with an 8 byte key) in CBC mode
with the given input vector
des ("8bytekey", "This is the message.", 1,
1, "inputvec");
//encrypt using triple DES (with a 24 byte key)
in ECB mode
des ("this is a 24 byte key !!", "This is the
message.", 1);
//decrypt using single DES in ECB mode
des ("8bytekey", "2384lf&*£90LSdsf", 0);
Source Code
There is no warranty for this code and neither
Laynetworks nor the auther of the code responsible
for any problems arising from using it (including
those caused by bugs). It has been tested to
see if it produces correct output, but has not
been robustly tested on different browsers,
processors, or with a wide range of keys and
messages. Any modifications to this code must
be posted on this site. If you find any errors,
bugs, security holes, or have any questions
or comments please email des@shopable.co.uk.
|