Thread: Bitswitching Encryption not working

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003

    Bitswitching Encryption not working

    ok first of all im not even sure its called bit switching, but whatever it is, it wont work
    the problem is, if i do the opposite of whatever i did to encrypt some text, it wont be back normal. im at school and dont have my code right now, but it was something to this effect:
    #include <iostream>
    #include <string>
    int main()
       char a[10];
       cin >> a;
       a >> 1;
       a += 5;
       cout << a << "\n";
       a -= 5;
       a << 1;
       cout << a << "\n";
       return 0;
    and it didnt work. then i figured that maybe the bitswitching was "pushing the character off the edge", or trying to make it go farther than the ascii characters go, and so there might be several characters there, and thus there might not be a unique character for each character they type in. maybe that doesnt sound very clear, but what i was trying to say was that i think bitswitching seems unreliable. how can i encrypt something in such a way that:
    a: it will be somewhat difficult to crack (not like a += 1 and thats it)
    2. i can unencrypt it with out problems
    iii- preferably, i wont have to write out a huge amount of code
    four~ i can use some sort of key/password thingy like other encryption uses i have seen.
    thank you for your help, and have a nice summer (unless you live south of the equator, cause dont they have winter now? that sucks, i hate winter)
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  2. #2
    Registered User
    Join Date
    Apr 2003
    It's called "bit shifting". Suppose 'a' looked like this:


    and then you performed a>>1

    that would give you:


    Now if you tried to reverse that with a<<1, you would get:


    which does not equal 111. The bitwise shift operators shift in zeros from the left and right. If that's your definition of "unreliable", then the bitwise shift operators are indeed unreliable. I like to think they are "reliable" because on Tuesday, they operate the same way as they did on Monday.
    Last edited by 7stud; 06-03-2003 at 03:20 PM.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Check out the XOR bitwise operation here for some simple encrypting:

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Originally posted by Salem

    The only information-preserving thing you can do is exclusive-or.
    Not entirely true. You can do rotations, but thats not a primitive operation.

    char rotate_left(char x, int amt)
        return (x << amt) | (x >> (sizeof(x) - amt));

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    I suppose it should be really
    return (x << amt) | (x >> ((sizeof(x)*CHAR_BIT) - amt));
    Good call. Can't believe I missed that.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. abt encryption algorithm
    By purIn in forum C Programming
    Replies: 9
    Last Post: 12-22-2003, 10:16 PM
  2. RSA Encryption
    By minesweeper in forum Tech Board
    Replies: 6
    Last Post: 08-30-2003, 01:48 PM
  3. Poor man's bitmap encryption
    By jdinger in forum Game Programming
    Replies: 8
    Last Post: 06-01-2002, 10:23 PM
  4. Encryption algorithyms
    By f0ul in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2002, 04:50 PM
  5. What's wrong with my Stream Cipher Encryption?
    By Davros in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2002, 09:51 PM