CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    41

    Adequate encryption?

    Hi

    I would like to be able to encrypt a double precision number and then save it to a binary file. Does anyone know whether or not it is secure to encrypt individual numbers? I'm guessing it is far more safer to encrypt a larger block of data.

    Cheers
    Robbie

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Adequate encryption?

    Of course. It doesn't make sense to encrypt a single number. If you want to do something at "number" level, mingle the bits. For instance switch bit 34 with 6, 8 with 9, 9 with 10, 10 with 1, XOR bits 45, 21 and 51, etc.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Adequate encryption?

    That's also why most encryption algorithms use blocks of data. When a block is not filled they often require you to pad the data with some padding byte to ensure 1 block.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Adequate encryption?

    It all depends on what you are trying to accomplish. A stream cypher like RC4 would work but might be overkill. A simple XOR with a static password might be sufficient. 8 chars is 64 bits. memcpy or cast your double to char and XOR character-wise:

    Code:
      double d=3.14159265;
      unsigned char *p,pw[]="abcdefgh";
    
      p=(unsigned char *)&d;
    
      for(int i=0;i<8;i++){
        p[i]^=pw[i];
      }
    To decrypt, just run it through again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured