Encryption suggestions?

This is a discussion on Encryption suggestions? within the C++ Programming forums, part of the General Programming Boards category; I need to design a final project to complete before Christmas vacation for my programming class. My teacher suggested I ...

  1. #1
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Encryption suggestions?

    I need to design a final project to complete before Christmas vacation for my programming class. My teacher suggested I write a program that encrypts and decrypts messages.
    Now, don't get me wrong, I'm not a helpless student programmer, and I'm not asking anyone to write any code for me. I'd just like some suggestions as to what encryption method to use. A comprehensive description of an algorithm or some pseudocode or a link to a good website would be greatly appreciated.

    A few considerations:
    This course is a first semester course in C++. Although I know how to use arrays and other things we haven't been taught in class, my teacher doesn't appreciate it when I use those concepts in my programs in his class.
    When I did a search of this forum and Google for encryption methods, I kept seeing ciphers using the XOR(^) operator. Although I would like to learn about it, my teacher wouldn't appreciate it if I used something like that that he didn't teach.
    My project needs to keep my interest untill Christmas break, so I need something more complicated than just a Caesar cipher.

    Sorry for the long post. I will be grateful for any help I get. Thank you.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Look up polygraphic system and Hill ciphers. The basic idea is that you divide the plaintext message into groups of letters and encipher the plaintext group by group. You can use matrix transformations in your encryption also. I don't really have time to explain it all though. You can find lots of good articles on it though. I don't know if this is the scope you're looking for or not. Good luck.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Mr. Wizard, thanks for the suggestion, but I'd like to stay away from matrix operations if at all possible. Somehow, none of my math teachers taught me anything about matrices all through high school. I'm not sure how that happened: I've always been in the highest level math classes and I'm a senior now.

    Anyway, I would be open to more suggestion, hopefully sans matrices.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    the encryption i use for my save games in my game is


    encryption:
    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <fstream.h>
    void EncryptString(char* String)
    {
       int Length = strlen(String);
       for(int i=0; i<Length; i++)
       {
          String[i]++;
       }
    }
    
    
    
    
    int main()
    {
     
     ofstream outfile;
     char encr[256];
     cout<<"Type a string to encrypt(type * and then enter to encrypt): ";
     cin.getline(encr, 256, '*');
     EncryptString(encr);
     outfile.open("encr.txt", ios::binary|ios::trunc);
     outfile<<encr;
     outfile.close();
     Sleep(3000);
     
     return 0;
     
    }
    decryption:
    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <fstream.h>
    #include <conio.h>
    #include <conio.c>
    #include <string.h>
    #define PASSWORD "password"
    void DecryptString(char* String)
    {
       int Length = strlen(String);
       for(int i=0; i<Length; i++)
       {
          String[i]--;
       }
    }
    
    int main()
    {
    ifstream infile;
    char encr[250];
    char pass[50];
    int fail;
    
     cout<<"A small hint...";
     cout<<"\n\nThe password is: "<<strlen(PASSWORD)<<" characters long";
     Sleep(2000);
     clrscr();
     cout<<"Password: ";
     cin>>pass;
     if(strcmpi(PASSWORD, pass) == 0)
     {
      cout<<"\n\nCorrect...";
      Sleep(2500);
      clrscr();
      cout<<"Encrypted Data: \n\n\n";
      infile.open("encr.txt", ios::binary);
      infile >> encr;
      infile.close();
      DecryptString(encr);
      cout<<encr;
      getchar();
      return 0;
     }
     else
     {
      while(strcmpi(PASSWORD, pass) != 0)
      {
      if(fail == 5)
      {
       clrscr();
       cout<<"\nSorry...";
       getchar();
       exit(1);
      }
      fail++;
      cout<<"\n\nIncorrect...";
      Sleep(2500);
      clrscr();
      cout<<"Password: ";
      cin>>pass;
      }
      cout<<"Correct...";
      Sleep(2500);
      clrscr();
      cout<<"Encrypted Data: \n\n\n";
      infile.open("encr.txt", ios::binary);
      infile >> encr;
      infile.close();
      DecryptString(encr);
      cout<<encr;
      getchar();
      return 0;
    }
    }

    for me that is unreadable enough...it becomes even worse when you save it as binary as well
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by devour89
    for me that is unreadable enough...it becomes even worse when you save it as binary as well [/B]
    For minor things (like game saves) that encryption will probably be a good choice, but if you want a higher level encryption, look up RSA encryption.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    GuestTrauts
    Guest
    If you want something extremely wimpy, try taking the input

    (say it is 0123456789 as a string)

    and rearrange it to

    0246813579

    Then do this:

    for (x=0; char[x] != '\0'; x++)
    char[x]=char(int(char[x])+1);

    that should add one to the ASCII value, making a very very simple encryption.

    Maybe then convert to binary and rearrange the characters again? Not very strong, but that should be material covered in the class

  7. #7
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    If you want to create a grown-up encryption program, see the following RC4 algorithm.

    http://www.columbia.edu/~ariel/ssleay/rrc4.html

  8. #8
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Davros
    If you want to create a grown-up encryption program, see the following RC4 algorithm.
    Although that seems to be a good idea, my class, unfortunately, hasn't covered structs, static, or pointers

    If you want something extremely wimpy. . .
    I don't want something extremely whimpy. I need something that will keep me busy untill Christmas break.

    Right now it looks like my top candidates are the Vigenere Cipher and RSA. If anybody can provide any more suggestions, I'm still open. Thanks to everyone for your help
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  9. #9
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >Although that seems to be a good idea, my class, unfortunately, hasn't covered structs, static, or pointers

    >Right now it looks like my top candidates are the Vigenere Cipher and RSA

    RSA? You mean public/private key? LOL. Implementing this will be a challenge, especially if you're not using pointers.

    Your best bet is a Vigenere Cipher.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. help needed with edit control & encryption
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 07:21 PM
  3. Constructive criticism, suggestions etc
    By BobS0327 in forum C Programming
    Replies: 3
    Last Post: 01-08-2006, 08:35 AM
  4. abt encryption algorithm
    By purIn in forum C Programming
    Replies: 9
    Last Post: 12-22-2003, 09:16 PM
  5. File Encryption & Read/Write in Binary Mode
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 05:45 PM

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