Fast EncryptionThe Encode and Decode are performed by the same function.
CRC4 implements an algorithm called Arcfour that is believed to be fully interoperable with the RC4 algorithm.
The Encrypt and Decrypt methods are only to demonstrate usage and are NOT the correct encryption. For the full Encryption use the CryptStream class which extends this class using the Rand several times.Usage:CString Key; CString Text; GetDlgItemText(IDC_Key,Key); GetDlgItemText(IDC_Text,Text); CRC4 RC4; RC4.Encrypt(Key,Text); SetDlgItemText(IDC_RC4, Data2ASCIIhex(Text)); RC4.Decrypt(Key,Text); SetDlgItemText(IDC_NewText,Text);
It must be strongly recommended that no two plaintexts are encrypted with the same key otherwise the plaintext can usually be broken, and often even quite easily. If the two encrypted messages are XORed together, the result is the XOR of the original plaintexts. Given the encrypted messages are text strings, credit card numbers, or other byte streams with some known properties, the plaintexts can be estimated with great accuracy. See [DAWSON AND NIELSEN] for more details.It uses another Pseudo-Random Number Generator (PRNG).
It is designed to produce random bytes to act on data streams.
CryptStream uses it.
CryptStreamThis is an implementation of an encryption algorithm called XOR256 that uses RC4.
CryptFile uses it.
A string of data can be encrypted or decrypted given a Key and Depth.
The Key is a String which can be short.
Increasing the Depth (an integer) makes the output harder to crack but slower to encode or decode.
Budding spies should be aware that if you save two files with the same Key and Depth then clever folks with time on their hands reckon they might be able to decode the data.
Usage:CCryptStream Stream; if(!Stream.SetDepth(12)) return; if(!Stream.SetKey("This is the Key")) return; char Text="This is the text"; int Len=strlen(Text); int Len1=Len>>1; int Len2=Len-Len1; Stream.Encrypt((BYTE*)Text,Text,Len1); Stream.Encrypt((BYTE*)Text+Len1,Text+Len1,Len2); Stream.Reset(); Stream.Decrypt(Text,(BYTE*)Text,Len);
CryptFileThis class overrides the MFC class CFile allowing XOR256 Encrypted files to be serialized.
It uses CryptStream.
Usage:CCryptFile File("gkcT1P8V",8); if(!File.Open("C:\\t.txt", CFile::modeRead)) return; CArchive ar(&File, CArchive::load); ar << CString("Hello World!") << (BYTE)123;
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.