simple encryption decrption
Results 1 to 4 of 4

Thread: simple encryption decrption

  1. #1
    Member
    Join Date
    May 2003
    Posts
    35

    simple encryption decrption

    i really hate c++ =p, but i am creating this program because of bordom, and to expand knowledge, i would like to know if anyone else can help with it, for some reason, its messed really bad,, or post some of your code for encryption too, anywho, this is really basic, just posting for fun, and it doesnt decrypt at all, but oh well

    /*
    Simple Encryption and Decryption

    */

    #include <iostream.h>


    int main()
    {
    char letter; // initial input
    int temp; //random input for crypto
    int i=0; // for counter and other counter
    int p; // temp var for counting and storing letters in let[]
    char let[100]; // storing words when encoded

    cout << "Enter Random Number" << endl; //////////////////////
    cin >> temp; // Simple input //
    cout << "Enter Text To Be Encrypted" << endl; //////////////////////

    for(p=0;letter != '5';p++) { // increases P everytime to keep up with letter does not equal 5
    cin >> letter; // simple input
    if('a' <= letter && letter <= 'z') { // if its not a and z it will quit
    letter = (letter - temp); // changes each letter to create an different character per character
    cout << letter;
    letter = let[p]; // set p to hold all input into a string as the encoded format
    }
    }
    cout << endl;
    for(i=0;i!=5;i++) { // loop 5 times to show different combos
    for(p=0;let[p] != '\n';p++) { //loop until end of line in array
    cout << let[p];
    }
    }
    return 0;
    }

  2. #2
    Senior Member
    Join Date
    Feb 2003
    Posts
    109
    First, if subtracting temp from the char generates a negative value, you're gonna have major issues. Secondly, "letter = let[p];" should be "let[p]=letter;" Also, you shouldn't use != in the last for loop, either use <,<=,>,>=. Its usually safer that way.
    $person!=$kiddie or die(\"Alas, die you hotmail hacker!!\");
    SecureVision

  3. #3
    Senior Member
    Join Date
    Dec 2001
    Posts
    134

    Re: simple encryption decrption

    Just a thought but using strings would make this code much more efficient, instead of looping until you hit the '\n' character you simply loop until you hit the end of the string. And out of curiosity, why does your encoding loop break when letter is '5'? Your loop will end everytime letter - temp becomes the literal value of 5.. again this would be solved by just looping through characters in a string, all you would have to do is manage each word which can be done a few ways, cin.peek() for example to see if there is a character entered, if there is then just add a space and then the next word. As infosecguru2 already pointed out your let[] array is empty because letter = let[p] should be the other way around. And what is this deal with combos? You're just looping through the same array 5 times and printing it.. Also you should add when encrypting so that the data never goes to negative numbers unless you are using integers or doubles to handle your encrypted data and keep it all in binary form instead of converting it to text because when you put it in a char type you can't print -ive numbers properly..

    I rewrote the code with what I thought you were trying to do but I may have missed something, was the basic algorithm to subtract your random number from any lowercase letter? Or was there more to it? Because there's a lot of garbage that didn't need to be there if that was the case.

    If my code has an error in it I'm sorry, but my compiler decided to not work (gotta love VC++, something else to fix soon)

    #include <iostream>
    #include <string>

    using namespace std;

    void main()
    {
    string letter
    int temp; //random input for crypto
    int i=0; // for counter and other counter
    int p; // temp var for counting and storing letters in let[]
    string let; // storing words when encoded

    cout << "Enter Random Number" << endl; //////////////////////
    cin >> temp; // Simple input //
    cout << "Enter Text To Be Encrypted" << endl; //////////////////////
    cin >> letter;
    while(cin.peek()) {
    letter += " ";
    cin >> let;
    letter += let;
    }
    let = "";
    for(p = 0; p < letter.length(); p++)
    {
    if('a' <= letter[p] && letter[p] <= 'z') { // if its not a and z it will quit
    let += (letter[p] - temp); // changes each letter to create an different character per character
    cout << let[p];
    }
    else { //could be a space or something, you'll lose detail without this
    let += letter[p];
    cout << letter[p];
    }
    }
    cout << endl;
    cout << letter[p]; //you were just printing out your encrypted text without doing anything to it..
    }
    Reality is the one who has it wrong, not you

  4. #4
    I'm very tired now, but at the first view i'll say that your program is very simple, and encrypts only a text that is included in the 'a' - 'z' charset. Probablly is not too hard to decrypt, but for me this will be a litle bit long time because i'll use a bactracking generation that will give me a large number of results.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •