tags:

views:

135

answers:

3

i need some idea for creatin a encryption program can any one help!? i need to create the program in java or c++ so need to create a logic for it this encryption prog should automatically encrypt the document n should decrypt it only if the givien conditions such as the password are fulfilled ! plz help !

+5  A: 

If its homework, you can do simple XOR with your pwd. Otherwise DONT! DONT mess with security stuff, DONT invent your own algo and DONT use ur own implementation of some well known methods. DO use something that has proven to be safe already.

atamanroman
+3  A: 

I agree with fielding. in case you want to do your homework, I think it's OK to use XOR encryption:

Java Sample Code:

public String xorEnc(int encKey, String toEnc) {
    /*
        Usage: str = xorEnc(integer_key,string_to_encrypt);
        Created by Matthew Shaffer (matt-shaffer.com)
    */
    int t=0;
    String s1="";
    String tog="";
    if(encKey>0) {
        while(t < toEnc.length()) {
            int a=toEnc.charAt(t);
            int c=a ^ encKey;
            char d=(char)c;
            tog=tog+d;
            t++;
        }

    }
    return tog;
}
public String xorEncStr(String encKey, String toEnc) {
    /*
        Usage: str = xorEnc(string_key,string_to_encrypt);
        Created by Matthew Shaffer (matt-shaffer.com)
    */
    int t=0;
    int encKeyI=0;

    while(t < encKey.length()) {
        encKeyI+=encKey.charAt(t);
        t+=1;
    }
    return xorEnc(encKeyI,toEnc);
}

you may want to start the decryption process only if the correct password entered, then you should somehow store the hash of decryption password on the encrypted file. for example your encrypted file may look like this:

[MD5 HASH OF PASSWORD][Encrypted Data]

then compare the entered password hash with the one you have saved, if they're identical start decryption process.

x86shadow
nice to have someone agree with me ;)but i wont give some "wrong password" message - why dont you XOR with the pw anyway? False results are harder to detect than error messages but easy to see if you know what should be the result. +1 for code sample
atamanroman
the problem here is tat in my school they hav thought the xor encryption so i think i wont be allowed to do it !
varun
yeh, but eventually you will face ROT-13 in advanced advanced crypto. What then? Reverse the data?
atamanroman
i din get u ! wats "advanced advanced crypto" ?
varun
A: 

if you like to do more advanced encryption/decryption you can have a look at nms-c/nms-d ( found at dotlike.net/releases.php )

it uses libcrypto and decrypts commands sent from a client (nms-c) and executes the command end send the encrypted output back to the client and prints it.

it uses base64-encoding/decoding before to transfer everything correctly.

blowfish encrypted is used.

dotlike.net