This one might be a cahllenge for you guys. Maybe?

This is a discussion on This one might be a cahllenge for you guys. Maybe? within the C++ Programming forums, part of the General Programming Boards category; Wencrypt(char* file) { char plaintext[1024], ciphertext[1024], password[1024]; ifstream fin(file); fin.close(); int strlngth = strlen(plaintext); ttyping(" What will the password be?", ...

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

    This one might be a cahllenge for you guys. Maybe?

    Wencrypt(char* file)
    {
    char plaintext[1024], ciphertext[1024], password[1024];

    ifstream fin(file);

    fin.close();
    int strlngth = strlen(plaintext);

    ttyping(" What will the password be?", 25, GRAY, YELLOW, WHITE, 7);
    cin>>password;

    for(int i = 1, opener = 0; i <= password[opener]; i++, opener++)
    {
    ciphertext[i] = password[opener];
    }

    ciphertext[0] = opener;

    for(i = i; i < strlngth; i++)
    {
    ciphertext[i] = plaintext[i] + 111;
    };

    ofstream fout(file);
    fout << ciphertext;


    return 0;

    }

    Wdecrypt(char* file)
    {
    char plaintext[1024], ciphertext[1024], password[1024], vpassword[1024];
    int opener;

    ifstream fin(file);

    fin.close();

    opener = ciphertext[0];
    int strlngth = strlen(ciphertext);

    for(int i = 1, k = 0; i <= opener; i++, k++)
    {
    vpassword[k] = ciphertext[i];
    }

    for(i = i; i < strlngth; i++)
    {
    ciphertext[i] = plaintext[i] - 111;
    };
    ciphertext[i + 1] = ' ';
    ciphertext[i + 2] = ' ';
    ciphertext[i + 3] = ' ';
    ciphertext[i + 4] = ' ';
    ciphertext[i + 5] = ' ';
    ciphertext[i + 6] = ' ';
    ofstream fout(file);

    fout << ciphertext;


    return 0;
    }


    these are my main functions for encrypting and decrypting. Some functions included in these functions you wont recognize, such as ttyping (because they are homemade), but I am having problems with this code. this is what im attempting to do:
    1. Ask for a Password to secure the file with
    2.Get the number of characters in the password.
    3.Put the number in the first char of the file
    4.Use the number to count how many letters are in the password when it is decrypted.
    5.decrypt the password
    6.verify the password
    7.if its correct, decrypt the file

    Any help on my coding would be greatly appreciated. Thx in advance

  2. #2
    Davros
    Guest
    > ciphertext[i] = plaintext[i] + 111;

    I believe this is what's called a mono-alphabet cipher. It's trivial to break this.

    Instead of shifting by a fixed value, what if you shifted by a pseudo random number? The initial seed you use could then be generated from your password.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    I was planning on doing that after i clear this bug i currently have. I will make it a 1024 bit encryption > muhaha

  4. #4
    Davros
    Guest
    This looks wrong:

    for(i = i; i < strlngth; i++)


    What do you mean by 1024 bit encryption? How do you plan to implement it?

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    using for loops to encrypt 1024 different random encryptions, stored various spots in the file, encrypted among themselves, decrypted in order and finally the message is decrypted. Get past that encryption and ill give you a cookie

  6. #6
    Davros
    Guest
    I've had a closer look at your code & can see somethings are wrong.

    1.
    for(i = i; i < strlngth; i++)

    what is i? It is out of scope of the previous loop. I don't think your code would compile, unless you declare i somewhere else not shown, in which case where do you initialise i?

    2.
    Wencrypt(char* file)
    {
    char plaintext[1024], ciphertext[1024], password[1024];
    ...

    Where do initialise the arrays? Surely you should be passing these to the Wencrypt function?

    3.
    Wdecrypt(char* file)
    {
    char plaintext[1024], ciphertext[1024], password[1024], vpassword[1024];
    int opener;

    ifstream fin(file);

    fin.close();
    ...

    I can't see where you actually read the file into the arrays.

    4.
    You don't seem to encrypt the password. Therefore, it will be visible at the start of the file. All you need to do is open it with a text editor.

    Also, as I understand it, 1024 bit encryption does not mean 1024 different random encryptions. Rather it means 2^1024 (or 1.797693134862315907729305190789e+308) different encryptions.

  7. #7
    Unregistered
    Guest
    actually you are really REALLY wrong. You shopuld get a life.. or learn to program C. The finished version is on another post. it has similar coding. go look at it

  8. #8
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > actually you are really REALLY wrong.

    Actually, YOU are. If 1024 bit encryption meant just 1024 possible choices, our gov't would have been screwed years ago (they only use 512, and the kind of encryption once considered unbreakable had only 52!)

  9. #9
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    argh, use code tags

  10. #10
    Davros
    Guest
    > The finished version is on another post. it has similar coding...

    I'm interested in this, where do I find the other post? (how old is it any keywords etc.. so I can a search)

    Denethor2000 - I have done a form of encryption myself. If you need further help, I would be willing to assist. Perhaps I'll learn some new thing in process.

  11. #11
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    512 bit encryption means 512 bits = 64 bytes in your key length (not necessarily password length), meaning you will have to try a maximum of 256^64 combinations to execute a brute force attack

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey guys, I'm new!
    By MrDoomMaster in forum C++ Programming
    Replies: 15
    Last Post: 10-31-2003, 04:47 PM
  2. How long have you guys been working with C/C++??
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 08-01-2003, 03:41 PM
  3. Tic Tac Toe -- Can you guys rate this please?
    By Estauns in forum Game Programming
    Replies: 2
    Last Post: 09-15-2001, 10:22 AM
  4. hello guys
    By lupi in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 06:42 AM
  5. hello guys
    By lupi in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2001, 01:00 AM

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