adding encryption to bmp

This is a discussion on adding encryption to bmp within the C Programming forums, part of the General Programming Boards category; hey ppl... well here's a chalenge; I made a XOR encryption program but I want to hide my encrypted file ...

  1. #1
    Registered User GiraffeMan's Avatar
    Join Date
    Feb 2002
    Posts
    20

    adding encryption to bmp

    hey ppl...
    well here's a chalenge; I made a XOR encryption program but I want to hide my encrypted file inside a bmp...

    the program should encrypt the file and then would, at the end of the bmp, add the encrypted file...

    I've got only one problem... what can I use to let the program reading the bmp (in binary) know where the encryption starts???
    and how can I be sure that other bmp viewers would'nt show that as curropted area in the bmp???

    I know it's a bit tricky but would help me a lot if you can give me the code....

    thanks in advanced
    THE GIRAFFE MAN
    "our heads in the skies, but our feet on the ground"....

    http://dagan.150m.com

  2. #2
    Unregistered
    Guest

    Throw that idea away!

    That way of hiding information is called "steganography".
    I donīt think your idea of hiding information isnīt a very good one. I think that your bitmap-files wonīt be read by most of the readers (my reader didnīt; I have tested it).
    There exist so much better ways (also for bitmap-file). Some of these methods are that good that you canīt proove that there is information hidden at all (thatīs the aim of stenography).
    My own stenographic way of hiding ASCII-text is the following:
    Windows (and the most other operating systems) print ' ' for the ASCII 32 (the "normal" character for space) and for the ASCII 160, I think. Now you can hide information in long enough text files by taking the space characters as bits: e.g. the character 32 is the bit 1 and character 160 is zero. Seven bits, I mean space-characters (or eight bits for other information than only text), are one character (ASCII 0-127). You can do that with other similar looking characters, if they exist.
    That way of steganography is rather secure, because text-files are often used and sent through the internet.
    Maybe you wanna implement it.
    I implemented it long time ago in QBasic.

    klausi

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    197

    Thumbs up itīs my reply

    I forgot to log in!

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

  4. #4
    Registered User GiraffeMan's Avatar
    Join Date
    Feb 2002
    Posts
    20

    thanks but...

    I didn't quiet get you there.. is there a code or a tutorial you can show me how to use that???
    THE GIRAFFE MAN
    "our heads in the skies, but our feet on the ground"....

    http://dagan.150m.com

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Here's the idea with a text file, you can do the same thing with audio, video, and static pictures as well though it takes a bit more work:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    static void ensteg ( void );
    
    int main ( void )
    {
      ensteg();
      return EXIT_SUCCESS;
    }
    
    void ensteg ( void )
    {
      FILE *crypt, *mask;
      int c, f, x, y;
      char bRaw[8], bRev[8];
      if ( ( mask = fopen ( "mask.txt", "r" ) ) != NULL &&
           ( crypt = fopen ( "ensteg.txt", "w" ) ) != NULL ) {
        printf ( "Enter a string\n" );
        while ( ( c = getchar() ) != EOF ) {
          for ( x = 7, y = 0; x >= 0; x--, y++ ) {
            while ( ( f = getc ( mask ) ) != (int)' ' )
              if ( f == EOF ) rewind ( mask );
              else (void)putc ( f, crypt );
            /* Break the byte down into bits and
            ** convert each bit into its char
            ** equivalent.
            */
            bRaw[x] = (char)!!( c & ( 1 << (unsigned)x ) ); 
            bRaw[x] = bRaw[x] % 10 + '0'; 
            bRev[y] = bRaw[x];
            /* Place the bit in the text file
            */
            if ( bRev[y] == '1' ) fprintf ( crypt, "%c ", f );
            else (void)putc ( f, crypt );
          }
        }
        /* Finish reading the mask file and close
        */
        while ( ( f = getc ( mask ) ) != EOF ) (void)putc ( f, crypt );
        fclose ( mask ), fclose ( crypt );
      }
      else
        printf ( "ERROR: File open failure\n" );
      printf ( "Press any key to continue" );
      (void)getchar();
    }
    The nice thing about this program is it's simplicity, each byte in a message is broken down into individual bits and printed as spaces accordingly. One space for binary 0 and two spaces for binary 1; the end result being a file that looks like it was badly formatted.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Unregistered
    Guest
    I think there is software that does this at:
    http://www.camouflagesoftware.co.uk/

  7. #7
    Registered User GiraffeMan's Avatar
    Join Date
    Feb 2002
    Posts
    20

    thank you all BUT...

    but.. . I'm still confused about the way... Isn't there any tutorial about this sort of stuff...
    Prelude I'm sorry but I can't grasp what your doing here!!!
    what do you mean by breaking the byte into bits and why would I use the spaces???

    sorry I'm still confused
    THE GIRAFFE MAN
    "our heads in the skies, but our feet on the ground"....

    http://dagan.150m.com

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    if your going to be converting each bit into a character, then arent you going to have a text file or whatever 8 times bigger than the original?

  9. #9
    Unregistered
    Guest
    You could check out 'Applied Cryptography' by Bruce Scnieder (spelling?).

    It's a great overview of security and has got plenty of source code to boot.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what do you mean by breaking the byte into bits and why would I use the spaces???
    My example was for text files only, the concept behind the program is that a char has a certain number of bits (8 was assumed in this program), each bit having either the value 0 or 1. The program uses this line
    bRaw[x] = (char)!!( c & ( 1 << (unsigned)x ) );

    to extract individual bits from an 8 bit char and places it in an array. The program then places each bit into a prewritten text file as a series of spaces in between the words, if the end of the file is reached before all of the bits are encoded as spaces then the file will rewind to the beginning and start over. So if you have the message "Hello", you can break each character into it's individual bits:
    H = 01001000
    e = 01100101
    l = 01101100
    l = 01101100
    o = 01101111

    Place this in a text file that already has something in it and you get a result similar to this:
    Code:
    Steganography is  the art of  hiding information in plain view  so  as 
    to confuse  seekers of  that information.  A  steganographic 
    program  is  one that places binary  data  in unlikely  places  
    such as the noise  of  an image  or  small  amounts  of static in a sound file.
    Take node of the unusual spacing, if you count the spaces where one space is a 0 and two spaces is a 1 and place them in groups of eight, you get this:
    01001000 01100101 01101100 01101100 01101111

    Which can then be converted to the ASCII equivalent, which is:
    Hello

    >arent you going to have a text file or whatever 8 times bigger than the original?
    Yes, which is why the program rewinds the file if it reaches the end and a much larger mask file hides the message better.

    -Prelude
    My best code is written with the delete key.

  11. #11
    Unregistered
    Guest
    I was just wondering, if you hide some text in a picture, how would you tell them apart?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  3. Problem reading BMP
    By Mortissus in forum C Programming
    Replies: 4
    Last Post: 02-02-2006, 06:32 AM
  4. Strange problem with bmp
    By Victor in forum Linux Programming
    Replies: 2
    Last Post: 04-04-2005, 03:48 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21