Basic encryption

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard

    Basic encryption

    I'm looking to do my own basic encryption. I've been tyring to do a
    concept such as:

    I pass this function the string, key and number of rounds I want to do
    the encryption. because im round shifting the bits the decryption
    doesn't work.. :P
    Am I going about this all wrong or does anybody know an easier way
    (besides getting an open source algo class such as Crypto++)

    I'm super new to fooling with the bits/encryption

    for(;num of rounds;)
    {
    char ^ Key;
    Round bit shift;
    }
  • Ivan Vecerina

    #2
    Re: Basic encryption

    "Richard" <shnuber@hotmai l.com> wrote in message
    news:3bcbbb8a.0 311121001.68f33 ed2@posting.goo gle.com...
    | I'm looking to do my own basic encryption. I've been tyring to do a
    | concept such as:
    |
    | I pass this function the string, key and number of rounds I want to do
    | the encryption. because im round shifting the bits the decryption
    | doesn't work.. :P
    | Am I going about this all wrong or does anybody know an easier way
    | (besides getting an open source algo class such as Crypto++)
    |
    | I'm super new to fooling with the bits/encryption
    |
    | for(;num of rounds;)
    | {
    | char ^ Key;
    | Round bit shift;
    | }

    What type of encryption you want to implement is not
    really clear to me.

    Just a few comments I can throw in:

    Watch that the bit-shift operators (<< and >>) actually lose
    data: they shift bits, and do not roll them.
    To implement rolling on a e.g. 32-bit value, you can use
    something like:
    *dst = (*src << nbits) | (*src >> (32-nbits) );
    Where *dst and *src shall be 32-bit unsigned integers,
    and nbits must be in [1..31].


    Not sure if it helps, but a 'simple' encryption source
    code can be found at: http://ivan.vecerina.com/code/coopfish/ .
    (implements the blowfish algorithm in a C++ fashion).


    hth-Ivan
    --
    Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



    Comment

    • J. Campbell

      #3
      Re: Basic encryption

      shnuber@hotmail .com (Richard) wrote in message news:<3bcbbb8a. 0311121001.68f3 3ed2@posting.go ogle.com>...[color=blue]
      > I'm looking to do my own basic encryption. I've been tyring to do a
      > concept such as:
      >
      > I pass this function the string, key and number of rounds I want to do
      > the encryption. because im round shifting the bits the decryption
      > doesn't work.. :P
      > Am I going about this all wrong or does anybody know an easier way
      > (besides getting an open source algo class such as Crypto++)
      >
      > I'm super new to fooling with the bits/encryption
      >
      > for(;num of rounds;)
      > {
      > char ^ Key;
      > Round bit shift;
      > }[/color]

      I just made a similar program, as vehicle to use to (try) to learn
      cpp). The code is zipped up at:

      Get the latest in news, entertainment, sports, weather and more on Currently.com. Sign up for free email service with AT&T Yahoo Mail.


      To compile it, include all the CPP files into a project then build it.
      int main() is in j_crypt.cpp. Or...you can drop a file on the exe
      file if you don't want to compile it yourself. This code will *not*
      modify/overwrite any files...it always gives them a new name.
      Anyway...this is what I came up with. slicerclass is a PRNG that can
      be used stand-alone, once initialized, the member function get_rand()
      returns a "random" unsigned long int.

      My prog may be a little more complicated than what you have in mind. I
      made use of a custom file-format that carries the original filename
      (encrypted) and a hash-value for the original file (also encrypted),
      so that authentication can be performed.

      I do not present this as model code, or as an example of learned
      cryptography. It happens to be where I stand in late 2003 on the
      learning curve. What this crypto will do is...take any file (even one
      filled with null bytes) and generate a stream of data
      indistinguishab le from "random" that contains the file info. Having a
      copy of both the plain and cypher-text won't help an attacker get the
      password. Successfully unencrypted files are authenticated. There is
      an inbuilt mechanism designed to make a dictionary attack difficult.
      cheers.

      Comment

      • Richard

        #4
        Re: Basic encryption

        Thanks guys,
        Ya i took into consideration when you shift you loose bits. I was
        justORing it with 0x80 for char to test if bit was 1/0 so i could tack
        it on the end i was shifting into.

        I should be able to get it right by trial and error.



        shnuber@hotmail .com (Richard) wrote in message news:<3bcbbb8a. 0311121001.68f3 3ed2@posting.go ogle.com>...[color=blue]
        > I'm looking to do my own basic encryption. I've been tyring to do a
        > concept such as:
        >
        > I pass this function the string, key and number of rounds I want to do
        > the encryption. because im round shifting the bits the decryption
        > doesn't work.. :P
        > Am I going about this all wrong or does anybody know an easier way
        > (besides getting an open source algo class such as Crypto++)
        >
        > I'm super new to fooling with the bits/encryption
        >
        > for(;num of rounds;)
        > {
        > char ^ Key;
        > Round bit shift;
        > }[/color]

        Comment

        • Ekkehard Morgenstern

          #5
          Re: Basic encryption


          Hi Richard,

          "Richard" <shnuber@hotmai l.com> schrieb im Newsbeitrag
          news:3bcbbb8a.0 311121001.68f33 ed2@posting.goo gle.com...[color=blue]
          > I'm looking to do my own basic encryption. I've been tyring to do a
          > concept such as:
          >
          > Am I going about this all wrong or does anybody know an easier way[/color]

          I've written numerous quite safe encryption (scrambling) algorithms. Don't
          use something too simple if you want to be safe. To test your encryption you
          could write a program that prints or displays image data. Then, encrypt an
          image and see what it displays then. If the original image is "shining thru"
          the algorithm is bad.

          I've had much success by using random numbers and loops that depend on
          previous data. You need at least two or more variables that are combined
          with the source data.

          You could do something like this:

          void simple_encrypt( int* dest, int* src, int count, int& v3, int& v4 )
          {
          int v1 = 0XFC03AB9D;
          int v2 = 0X4903CB0A;
          v3 = rand();
          v4 = rand();
          for ( int i=0; i<count; ++i ) {
          int v = *src++;
          v = ( ( v1 ^ v ) - ( v2 ^ v ) + ( v3 - v1 ) - ( v1 + v4 ) );
          v1 ^= v2 + v3;
          v2 ^= v1 - v4;
          v3 -= v1 + v2;
          v4 += v2 - v1;
          *dest++ = v;
          }
          }

          You would have to keep the values of v3 and v4 elsewhere to be able to
          decode the data later on. The encoding should be designed such of course
          that you can reverse all operations.

          The code I gave is just an example how you could do it, just play around
          with various combinations of +, - and XOR (^). Those are easier to do in
          reverse than other operations.

          Have fun! :)
          I hope this helped! :)

          Regards,
          Ekkehard Morgenstern.


          Comment

          • Ekkehard Morgenstern

            #6
            Re: Basic encryption

            BTW, for random number generation, you could (if you're programming for the
            IA-32 architecture, like Pentium 1-4), use the processor's uptime counter in
            the seed value:

            __int64 GetProcessorClo ck( void ) { _asm rdtsc; }
            void SetRandomSeed( void ) { srand( (unsigned)( time(0) ^
            GetProcessorClo ck() ) ); }

            The value from RDTSC is unsuitable for using in loops, because it increments
            with each processor cycle. If your routine uses a fixed amount of cycles,
            the results might be predictable. But you can use it in an initial value.
            ;-)



            Comment

            • Ivan Vecerina

              #7
              Re: Basic encryption

              "Ekkehard Morgenstern" <ekkehard.morge nstern@onlineho me.de> wrote in message
              news:bp19pi$j4c $1@online.de...
              | I've written numerous quite safe encryption (scrambling) algorithms. Don't
              | use something too simple if you want to be safe. To test your encryption
              you
              | could write a program that prints or displays image data. Then, encrypt an
              | image and see what it displays then. If the original image is "shining
              thru"
              | the algorithm is bad.
              |
              | I've had much success by using random numbers and loops that depend on
              | previous data. You need at least two or more variables that are combined
              | with the source data.

              The "Secure Programming Cookbook" of John Viega & Matt Messier has
              a free chapter about random numbers available online:
              http://www.oreilly.com/catalog/secureprgckbk/ (book page)

              I also vaguely remember, from reading TAoCP, Knuth stating something
              like "Don't use a random approach to generate random numbers".

              For both encryption and random number generation, which are closely
              related, I would rather rely on published and well-studied algorithms.

              I'm not a cryptanalyst, and I am confident that an expert can do much
              better than me. Too many commercial (and free) applications/OSes
              suffered security loopholes because of weak random number generation.
              I don't trust myself to invent something better...


              This said: the OP was asking for 'basic encryption' -- and your post
              and suggestions are very helpful and fully relevant in this context :)


              Kind regards,
              Ivan
              --
              Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



              Comment

              Working...