mcrypt something like –s"fjf
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
mcrypt something like –s"fjf
Can anyone help me in encrypting a string that is like this: ¡“„Œ
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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:
EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.
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;
}Why?feyd wrote:Sorry to say it, but a xor based encryption is hardly that.
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 youtecktalkcm0391 wrote:EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.
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.
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
I try doing encode("adadf832!@#%@adfkasdhkdgf"); and I get the error. I am trying to get that to work.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.
lol. I didn't relize I read it wrong I'll have to do the OTP stuff then...Mordred wrote:Lol, you picked the defining authority on the subject, didn't youtecktalkcm0391 wrote:EDIT: Read: http://forums.gamemaker.nl/lofiversion/ ... 63790.html and it says its good. Not the best, but good.
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.
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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:
And I want to run this, but I get errors [Pack of % is not valid (or something like that):
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;
}Code: Select all
$input = ': ¡“„Œ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 = '¡“„Œ- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
[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 = '¡“„Œ