Page 1 of 1

mcrypt something like –s"fjf

Posted: Mon Feb 19, 2007 9:15 pm
by tecktalkcm0391
Can anyone help me in encrypting a string that is like this: ¡“„Œ

Posted: Mon Feb 19, 2007 9:39 pm
by feyd
A key for every character? Image

What have you tried?

Posted: Mon Feb 19, 2007 9:50 pm
by tecktalkcm0391

Code: Select all

FUNCTION ENCRYPT_DECRYPT($Str_Message) { 
    $Len_Str_Message=STRLEN($Str_Message); 
    $Str_Encrypted_Message=""; 
    FOR ($Position = 0;$Position<$Len_Str_Message;$Position++){ 
        // long code of the function to explain the algoritm 
        //this function can be tailored to modifyng the formula 
        //to calculate the key to use for every character in the string. 
        $Key_To_Use = (($Len_Str_Message+$Position)+1); // (+5 or *3 or ^2)  EDIT THIS LINE TO CHANGE THE KEY TO CHANGE WHOLE ENCRYPTION
        //after that we need a module division because can´t be greater than 255 
        $Key_To_Use = (255+$Key_To_Use) % 255; 
        $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1); 
        $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted); 
        $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use;  //xor operation 
        $Encrypted_Byte = CHR($Xored_Byte); 
        $Str_Encrypted_Message .= $Encrypted_Byte; 
        
        //short code of  the function once explained 
        //$str_encrypted_message .= chr((ord(substr($str_message, $position, 1))) ^ ((255+(($len_str_message+$position)+1)) % 255)); 
    } 
    RETURN $Str_Encrypted_Message; 
} //end function
Also, do you know how to get the MCRYPT to work, anyone? Please help!

Posted: Mon Feb 19, 2007 10:04 pm
by feyd
Sorry to say it, but a xor based encryption is hardly that.

What have you attempted to get mcrypt working so far?

Posted: Mon Feb 19, 2007 10:21 pm
by tecktalkcm0391
To tell you the truth, nothing. I can't seem to find any functions to do anything to help. Pack() and Unpack() are confusing me, and I don't think that bin2hex() will work either.

But this is what I am using:

Code: Select all

DEFINE ("Keysize","23r!j09$%^@#30"); // This is made by something else

function encode($data) 
{ 
        $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, ""); 
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); 
        $encdata = mcrypt_ecb (MCRYPT_TripleDES,(Keysize), $data, MCRYPT_ENCRYPT, $iv); 
        $hextext=bin2hex($encdata); 
        return $hextext; 
} 

function decode($data) 
{ 
        $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, ""); 
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); 
        $dectext = rtrim(mcrypt_ecb (MCRYPT_TripleDES,(Keysize), pack("H" . strlen($data), $data), MCRYPT_DECRYPT,$iv), "\0"); 
        return $dectext; 
}
feyd wrote:Sorry to say it, but a xor based encryption is hardly that.
Why?
EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.

Posted: Mon Feb 19, 2007 11:25 pm
by feyd
Considering the value of $Key_To_Use is a linear equation, the encryption is extremely trivial. It's not a good one at any level.

As for your attempts at mcrypt, what's not working? They look fine from a quick glance.

Posted: Tue Feb 20, 2007 5:19 am
by Mordred
tecktalkcm0391 wrote:EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.
Lol, you picked the defining authority on the subject, didn't you ;)
You haven't yet learned the first lesson of the young cryptographer: "Don't make your own homebrew encryption methods, they WILL suck".

OTP is the best encryption method, provided it is implemented correctly, and both parties have other means of transporting the pads. While XOR can be used in an OTP encryption, its key feature is the one-time pad, not the XOR. What you did has nothing to do with OTP.

Posted: Tue Feb 20, 2007 7:45 pm
by tecktalkcm0391
feyd wrote:Considering the value of $Key_To_Use is a linear equation, the encryption is extremely trivial. It's not a good one at any level.

As for your attempts at mcrypt, what's not working? They look fine from a quick glance.
I try doing encode("adadf832!@#%@adfkasdhkdgf"); and I get the error. I am trying to get that to work.

Mordred wrote:
tecktalkcm0391 wrote:EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.
Lol, you picked the defining authority on the subject, didn't you ;)
You haven't yet learned the first lesson of the young cryptographer: "Don't make your own homebrew encryption methods, they WILL suck".

OTP is the best encryption method, provided it is implemented correctly, and both parties have other means of transporting the pads. While XOR can be used in an OTP encryption, its key feature is the one-time pad, not the XOR. What you did has nothing to do with OTP.
lol. I didn't relize I read it wrong I'll have to do the OTP stuff then... :)

Posted: Tue Feb 20, 2007 9:25 pm
by volka
'll have to do the OTP stuff then...
Are you sure? OTP means your key is (at least) as long as the plaintext, sufficiently random, exchanged through a secure channel before the encrypted message is sent and only used once.

Posted: Wed Feb 21, 2007 7:00 am
by tecktalkcm0391
For right now, I am going to forget about all this other stuff. Can someone just help me get this to work:

I have this:

Code: Select all

DEFINE ("Keysize","23r!j09$%^@#30"); // This is made by something else 

function encode($data) 
{ 
        $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, ""); 
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); 
        $encdata = mcrypt_ecb (MCRYPT_TripleDES,(Keysize), $data, MCRYPT_ENCRYPT, $iv); 
        $hextext=bin2hex($encdata); 
        return $hextext; 
} 

function decode($data) 
{ 
        $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, ""); 
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); 
        $dectext = rtrim(mcrypt_ecb (MCRYPT_TripleDES,(Keysize), pack("H" . strlen($data), $data), MCRYPT_DECRYPT,$iv), "\0"); 
        return $dectext; 
}
And I want to run this, but I get errors [Pack of % is not valid (or something like that):

Code: Select all

$input = ': ¡“„Œ

Posted: Wed Feb 21, 2007 7:18 am
by volka
try

Code: Select all

<?php
DEFINE ("Keysize","23r!j09$%^@#30"); // This is made by something else
srand();

function code($data, $bEncode=true) {
	$td = mcrypt_module_open('tripledes', '', 'ecb', '') or die('mcrypt_module_open failed');
	
	$key = (mcrypt_enc_get_key_size($td)<strlen(Keysize)) ? substr(Keysize, 0, mcrypt_enc_get_key_size($td)) : Keysize;
		
	$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND) or die('mcrypt_create_iv failed');
	if ( 0>mcrypt_generic_init($td, $key, $iv) ) {
		die('mcrypt_generic_init failed');
	}
		
	$retval = $bEncode ? mcrypt_generic($td, $data) : mdecrypt_generic($td, $data);
	
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	
	return $retval;
}

$input = '¡“„Œ

Posted: Wed Feb 21, 2007 3:29 pm
by tecktalkcm0391
[quote="volka"]try

Code: Select all

<?php
DEFINE ("Keysize","23r!j09$%^@#30"); // This is made by something else
srand();

function code($data, $bEncode=true) {
	$td = mcrypt_module_open('tripledes', '', 'ecb', '') or die('mcrypt_module_open failed');
	
	$key = (mcrypt_enc_get_key_size($td)<strlen(Keysize)) ? substr(Keysize, 0, mcrypt_enc_get_key_size($td)) : Keysize;
		
	$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND) or die('mcrypt_create_iv failed');
	if ( 0>mcrypt_generic_init($td, $key, $iv) ) {
		die('mcrypt_generic_init failed');
	}
		
	$retval = $bEncode ? mcrypt_generic($td, $data) : mdecrypt_generic($td, $data);
	
	mcrypt_generic_deinit($td);
	mcrypt_module_close($td);
	
	return $retval;
}

$input = '¡“„Œ