Thread: Encryption

  1. #1
    Registered User
    Join Date
    Mar 2002

    Smile Encryption

    Dear Everyone,

    Can someone give me a simple example for encrypt the "Hello",
    I've download the "encrypt.c", but so hard for me,
    please who can give me the simple one.


    * File: encrypt.c
    * Date: 8 May 1999
    * Author: Bret Taylor (
    * -------------------------------------------
    * This is the implementation for the encrypt.h library. This
    * library uses bit manipulation to consistently map characters
    * to an unreadable format that is also 8 bits in length. It does
    * so with the bitwise XOR operator (^), which returns which bits
    * are on in the first operand, but not in both. The useful thing
    * about this operator is that a variable XOR'd with another can be
    * returned to its original state simply by XORing it with that
    * variable again. Hence, this library (internally, anyway) doesn't
    * even make a distinction between encrypting and decrypting (both
    * simply require XORing each character in the input file)!

    #include "encrypt.h"
    #include <assert.h>

    /* Private Function Prototypes */
    static void ApplyKeyToFile(FILE *in, FILE *out, unsigned char key);

    * Public Function: EncodeFile
    * ---------------------------
    * This function is simply a wrapper function for the ApplyKeyToFile
    * decoder/encoder function.
    void EncodeFile(FILE *textFile, FILE *outputFile, unsigned char key)
    assert(textFile && outputFile);
    ApplyKeyToFile(textFile, outputFile, key);

    * Public Function: DecodeFile
    * ---------------------------
    * This function is simply a wrapper function for the ApplyKeyToFile
    * decoder/encoder function.
    void DecodeFile(FILE *encodedFile, FILE *outputFile, unsigned char key)
    assert(encodedFile && outputFile);
    ApplyKeyToFile(encodedFile, outputFile, key);

    * Function: ApplyKeyToFile
    * ------------------------
    * This function reads in characters from the in file, applying
    * the bitwise XOR operator on each. It then writes those characters
    * to out. Read this file's comments for a detailed explanation why
    * this function makes no distinction between "encoding" and
    * "decoding".
    static void ApplyKeyToFile(FILE *in, FILE *out, unsigned char key)
    int ch;

    while ((ch = getc(in)) != EOF)
    putc(ch ^ key, out);

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    All this does is take a character and XOR it with a value. It does this with every charater in the file. If you understand how a bitwise XOR works, then you can understand this function.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Here is something else about the XOR-encryption and its application.

    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. help needed with edit control & encryption
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 08:21 PM
  3. abt encryption algorithm
    By purIn in forum C Programming
    Replies: 9
    Last Post: 12-22-2003, 10:16 PM
  4. What's wrong with my Stream Cipher Encryption?
    By Davros in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2002, 09:51 PM
  5. File Encryption & Read/Write in Binary Mode
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 06:45 PM