Results 1 to 13 of 13
  1. #1
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow

    [Help]C++ bit shifting

    So I wrote a program which encrypts text using a completely different method which I now figured could be somewhat easily decrypted with a decent pc. However I think I know of a way to use bit shifting to make it near impossible. I looked everywhere for an answer but I didn't really find one.

    Basically how would you make sure to take the bit that falls off and slap it onto the next byte. The best solution I can think of is this:

    say you have the value
    1001 1110
    you want to shift it left by 2
    so you put it in a loop

    loop_of_some_sort
    {
    1001 1110 & 1100 0000 = some_var
    some_var / 64
    1001 1110 * 2 = some_var2
    some_var2 or some_var = some_var
    }

    Now you should have it shifted left by 2 and you didn't loose the bits. I threw that pseudo code together while writing this post so it might be wrong.

    Does anyone know of a simpler way?

  2. #2
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Bit shifting in C++:

    [php]
    int var = 0xFFFFFFFF;
    var << 2; //shift left
    [/php]

    Not sure what you're asking though.

  3. #3
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    would that turn
    1111 0000
    into
    1100 0000
    or
    1100 0011

    I was under the impression it just cuts the bits off that are shifted or are the placed in the next byte?

  4. #4
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    I don't know how to do precision bit shifting in C++, only assembly.

    Precision shift:
    [php]
    mov eax,11110000b
    mov ebx,11111111b
    shld eax,ebx
    [/php]

    result: 11100001

    Normal shift:
    [php]
    int var = 11111111b; //assuming this is binary
    var << 1;
    [/php]

    result: 11111110

    I think, did this off the top of my head.

  5. The Following User Says Thank You to Void For This Useful Post:

    hobosrock696 (10-03-2010)

  6. #5
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    Hmmm well then I guess I'll have to start looking into assembly or use my overly complex way to do this :/

  7. #6
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    Quote Originally Posted by hobosrock696 View Post
    Hmmm well then I guess I'll have to start looking into assembly or use my overly complex way to do this :/
    Lol, as long as it works I guess it's fine.

  8. #7
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    Oh if I knew if it worked that would be nice.... Will find out tomorow haha wana play with the program I have for now? Simple little thing and unfortunately makes the output 2 times the size of the input due to the method I used 0.o

  9. #8
    -Raz0r-'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Australia
    Posts
    117
    Reputation
    15
    Thanks
    38
    My Mood
    Lurking
    Ah, I worked on a small encryption algorithm that used this..
    But a word of advice, I wouldn't use any self-made 'encryption' algorithms in a real world application of any sort, unless you've been studying advanced cryptography for 20 years.

    [php]data[i] = (data[i] << 3) | ((unsigned char)data[i] >> 5); // (11001010 -> 01010110)[/php]

    =D
    Languages: C, C++, x86 ASM, PHP, Lua

  10. The Following 2 Users Say Thank You to -Raz0r- For This Useful Post:

    hobosrock696 (10-04-2010),Void (10-04-2010)

  11. #9
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    Hehe yes yes well the worst that can happen is it will never be used right?

    Ahhhhh your solution is so much more... elegant....

    EDIT: Hey razor you wouldnt be able to look at what I did and tell me why its way to decryptable would you? I can already take guesses at why but I would like a second opinion...
    Last edited by hobosrock696; 10-04-2010 at 06:00 AM.

  12. #10
    -Raz0r-'s Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Australia
    Posts
    117
    Reputation
    15
    Thanks
    38
    My Mood
    Lurking
    Well I'm no professional, but I'm going to guess your algorithm is easily reverse engineered.
    That's enough for someone to write a decrypter, if you haven't already included a decrypter in the program for them =p
    I think the most vulnerable parts of encryption would be reverse-engineer-ability and having a weak key.

    If just for fun, look into public key/private key systems, 'salts', etc.
    Cryptography is a fun subject I looked into at some point, but I do accept that you need a very strong background in cryptography for any algorithm to be used in a real-world application.
    Languages: C, C++, x86 ASM, PHP, Lua

  13. #11
    .::SCHiM::.'s Avatar
    Join Date
    Sep 2010
    Gender
    male
    Posts
    733
    Reputation
    180
    Thanks
    880
    My Mood
    Twisted
    You can also use inline asm to rotate or shift
    Code:
    var 1  //binary 
    var 2 //places to shift
    __asm{
    mov al, var1
    shl al, var2 ; shifts to the left 
    mov var1, al
    }
    But I don't think you want to shift your bytes, since they'll fall of your string (leaving 0's on the right side)

    You'd want to rotate:
    Code:
    var 1
    var 2
    __asm{
    mov al, var1
    rol al, var2 ; Rotates to the left (bits that would fall off your string are appended to the other side, however they are appended in reverce order
    mov var1, al
    }

    I'm SCHiM

    Morals derive from the instinct to survive. Moral behavior is survival behavior above the individual level.

    Polymorphic engine
    Interprocess callback class
    SIN
    Infinite-precision arithmetic
    Hooking dynamic linkage
    (sloppy)Kernel mode Disassembler!!!

    Semi debugger




  14. #12
    doofbla's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    Biel*****/Germany
    Posts
    369
    Reputation
    10
    Thanks
    179
    My Mood
    Psychedelic
    I just knew the method VOID posted

    00001111;

    << 4

    11110000

    so <<1 would be similary to *2 and <<2 = *4 and <<X = *2^X

    or is that false?
    _____________________________________________

    READING TUTORIAL:

    1. READ MY POST
    2. THINK ABOUT MY POST
    3. PRESS THANKS
    4. MAYBE CORRECT MY POSTS :P




    Dijkstra:
    "Computer Science is no more about computers than astronomy is about
    telescopes."


    THANKS BUTTON RIGHT DOWN --->

  15. #13
    hobosrock696's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    45
    Reputation
    9
    Thanks
    1
    My Mood
    Mellow
    Well hrmm I know how to rotate with one byte im working on some code that will rotate any amount of bytes by any amount. Now as for my encryption method it uses a "password which can be up to the length of the content being encrypted. There is no set key length. Without the key its all guess and check. Either way I am still rewriting it to make it ever so slightly harder to guess and check. I think maybe a few times harder to guess and check...

    EDIT: also the bytes are encrypted in lengths of the key. The fact that the encryption repeats over and over with a short key would make it vulnerable since you could look for patters BUT if the key is long enough its difficult.... I will also be bit shifting a LOT of bits at a time in directions based off the key. Then just scramble the bytes up and you're done. Note this is not an encryption program written with the internet in mind but rather safekeeping. Over the internet you would have to send a key which would be decrypted and therefore the file would easily be decrypted.

    Off to work on the one that encrypts files....
    Last edited by hobosrock696; 10-04-2010 at 06:43 PM.

Similar Threads

  1. [Solved] Help windows 7 x64 bits
    By Codder in forum Combat Arms Brazil Help
    Replies: 0
    Last Post: 10-22-2011, 03:14 PM
  2. Bit shifting
    By Void in forum Assembly
    Replies: 12
    Last Post: 12-13-2009, 01:10 AM
  3. A bit of help with packets
    By lapa321 in forum WarRock - International Hacks
    Replies: 3
    Last Post: 02-19-2008, 01:44 PM
  4. warrock helps hus a little bit.
    By SHadyDAGGER in forum WarRock - International Hacks
    Replies: 3
    Last Post: 01-26-2008, 11:46 AM
  5. bit of help plz....
    By prox32 in forum WarRock - International Hacks
    Replies: 8
    Last Post: 04-24-2007, 04:12 PM