Encryptor\Decryptor

This is a discussion on Encryptor\Decryptor within the C++ Programming forums, part of the General Programming Boards category; KEWL!! thanks to you guys i have made an encrypter/decrypter . It works well on .txt files! plz try it ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    Talking Encryptor\Decryptor

    KEWL!! thanks to you guys i have made an encrypter/decrypter . It works well on .txt files! plz try it and tell me what u think. It doesnt work on programs yet because sometimes a character or 2 add on to the end of the file. If you could tell me how to take them off i'd really appreciate it! thx in advance
    Attached Files Attached Files

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230

    Bad boy

    First of all, it doesn't work. Second of all, you overwrite the file you are encrypting. That is totally bad, especially when your decryptor doesn't work.

    So you should save the encrypted text to a new file name like filename-ciphered.txt. Or you should prompt for the filename to save the ciphered text to.

    Here.. I have included an XOR encrypting program that works (most of the time). The problem with XOR encryption is that the ciphered text is completley unpredictable and can sometimes put in characters that you don't want (like newlines and terminators). But you can look at it to get a picture of some good ideas for an encryption program. I hope that helps.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    well you're partly right

    it DOES work - but it doesnt accept spaces, and it adds 1 or 2 characters after the word lol

  4. #4
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Ahh, see I encrypted a text file that had many a space. It took a 25 character file and encrypted it to like 5 characters. Then, when I tried to decrypt it, it was still garbage.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    yah :/ do you know how to make it encrypt and decrypt spaces?

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    It does encrypt but it doesn't decrypt for me.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  7. #7
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I am running XP just in case that might be a reason why.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    naw, im using xp and works 4 me. you need to may it 1 word :/ if you want to write a sentace try-writing-it-like-this. it works

  9. #9
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    When I wrote my first rot13 encrypting program, I just skipped over the spaces.. As a matter of fact, hold on...... Ok, I got the algorithm I made for it:

    Code:
       /* 
        * Begin getting text from user and char-by-char encrypting
        */
       while ((c = getchar()) != '\n')
       {
          if (!isspace(c))  // If its a space, there is no need to shift 
          {  
             if (isalnum(c))  // Make sure it's an alpha-numeric
             {    
                if (   c == 'x' || c == 'X' || c == 'y' || c == 'Y' || c == 'z' || c = 'Z' )
                   *cipher++ = (c - 23);
                else
                   *cipher++ = (c + 3);
             }
          }
          else
             *cipher++ = c; // Leave it alone if it is a space
       }
    The main idea is to use the ctype (or the cctype for ANSI C++) functions isspace(), isalnum(), etc.. to test the character and do certain things based on the returns of those functions. I'm sorry if you can't understand the code. I wrote it a long, long time ago and it's C. Plus you probably have to understand Caesarian encryption (which isn't that hard to understand).

    So basically test for spaces and don't encrypt them, just leave them alone and let them be spaces in the encrypted text.

    I hope that helps.

    EDIT:: Please do not flame me for this piece of code. I realize how lame it is and how unstructured it is (with 3 thresholds of indentation), but it works and it helps express my point.
    Last edited by biosx; 03-19-2002 at 05:34 PM.

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    *ciphertext++ = c; // Leave it alone if it is a space


    in this line of code i need to know what c is :/ and ++ needs an l-value

  11. #11
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Look at the top of the program block..

    Code:
    while ( (c = getchar()) != '\n' )
    {
       // etc. etc.
    }
    c is a character that has been read from the user's input.

    I don't know why the compiler is whining about *ciphertext++. To change it around replace it with this:
    Code:
    *ciphertext = c;
    ciphertext++;
    I hope you aren't trying to incorporate this into anything. It is based on a completley different scheme than what you were using.

  12. #12
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    i tried :

    for(int i = 1; i < strlngth; i++)
    {
    if (!isspace(ciphertext[i]))
    {
    ciphertext[i] = plaintext[i] - opener;
    }
    else
    ciphertext[i] = '';
    };

    but it just prints everytime i type in a space in the file. ass int is the WHOLE file :/

  13. #13
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Why do you subtract 'opener'?

    Just leave it:
    Code:
    for(int i = 1; i < strlngth; i++) 
    { 
       if (!isspace(ciphertext[i]))  
          ciphertext[i] = plaintext[i];  
       else 
          ciphertext[i] = ''; 
    };

  14. #14
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    opener is a random number. it sits at the beginning of the file and when it gets opened it reads the number and subtracts it. therefore ytou must add it in the other or it will come out random again ^_^

  15. #15
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230


    Did you even try NOT subtracting opener?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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