Get support from Xavier Media
It is currently Sun Dec 08, 2013 3:47 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Encrypter with password
PostPosted: Tue Dec 12, 2006 6:03 pm 

Points:
I've made a script 4 encrypting text, needing to know the password (or do realy much math :P ) to get out the meaning of the message... Only works on php5 though... If any1 has a solution on how to make this work on php4 let me know... Anyway... The script consists of 5 functions... The first one (very easy) is just getAlfabet.
PHP Code:
function getAlfabet(){
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?,.:;' ".'"';
}

Than I've got a function called myEncrypt($string). This looks a bit essy, but I hop you all understands...
PHP Code:
<?PHP
function myEncrypt($string){
$array = str_split($string);
/*Splitting the strings up in arrays*/
$alfa = str_split(getAlfabet());
/*Counting the length of both arrays*/
$num = count($array);
$nom = count($alfa);
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($array[$i] == $alfa[$b]){
$allNums .= "$b|";
/*Checking to see if the letter is equal
to anny of the letters in $alfa*/
};
};
};
$text = explode("|",$allNums);
/*Makes the numbers that are gennerated in the for loop(s)
into an array*/
$num = (count($text))-1;
/*Setting a new num*/
$add = rand(0,1000);
/*Pikking a random number between 0 and 1000 to add to all the $text
numbers */
$to = 1;
$togo = 1;
while ($togo != 0){
while ($to < 1000){
if (($add / $to) == $nom){
$togo = 2;
};
$to++;
};
$togo--;
if ($togo != 0){
$add = rand(0,1000);
};
};
/*Scecking to see that $add is not dividabel to $nom*/
$encrypted = "$add|";
/*Starting the encryptedvariable*/
for ($i=0;$i<$num;$i++){
$thisNum = $add + $text[$i];
while ($thisNum >= 0){
$thisNum -= $nom;
/*Substracting $nom from $thisNum until $thisNum is less
than zero, than we add $nom... This is to make shure that
$thisNum stays between 0 and $nom without loosing it
value (the letter it is representing)*/
};
$thisNum += $nom;
$encrypted .= $alfa[$thisNum];
/*Getting whatever letter is stored at the position of the number
mad to encrypt, the number whitch is between 0 and $nom and adds
this $encrypted*/
};
return ("$encrypted");
/*Returning the encrypted*/
};
?>

Than I've got the decrypt function... I sugest that you keep both the 'my~' functions in a separate file, so that peoples can not get theirs hands on them... If you get to know a 'my~' function you can get peoples password... Anyway... myRecrypt($cryptedArray)
PHP Code:
<?PHP
function myRecrypt($cryptedArray){
$array = explode('|',$cryptedArray);
/*Making the variable '245|flkjHK91?!' into an array of two fields*/
$add = $array[0];
/*Setting the variable add to the number in front of the encryption*/
$text = str_split($array[1]);
/*Splitting the second part of the array up to a new array*/
$alfa = str_split(getAlfabet());
/*Getting the alfabet and splitting it*/
$num = count($text);
$nom = count($alfa);
/*Counting both $text and $alfa*/
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
/*Getting the number for that carracter*/
$thisNum -= $add;
/*Substracting $add from the number*/
while ($thisNum < 0){
$thisNum += $nom;
/*Adding $nom to the number untill it's greater than 0*/
}
$allNums .= $alfa[$thisNum];
/*Adding the coresponding letter to $allNums*/
};
};
};
return ($allNums);
/*Returning $allNums*/
};
?>

Than you've got the two functions you want to call when you want to encrypt or decrypt (recrypt :P ) somthing... passEncrypt($pass, $message) and passRecrypt($pass, $encrypted)...
PHP Code:
<?PHP
function passEncrypt($password,$message){
$pass = myEncrypt($password);
/*Encrypting the password*/
$mess = myEncrypt($message);
/*Encrypting the message*/
$encrypted = "$pass/$mess";
/*Making a variable to hold them both*/
return ($encrypted);
/*Returning the result*/
};
function passRecrypt($pass,$encrypted){
$mid = explode('/',$encrypted);
/*Deviding into password and message*/
$cryptedPassArray = $mid[0];
$cryptedMessageArray = $mid[1];
$password = myRecrypt($cryptedPassArray);
/*Recrypting the password*/
$message = myRecrypt($cryptedMessageArray);
/*Recrypting the message*/
if ($pass == $password){
/*If the password maches, than return the message*/
return ($message);
} else {
/*else return 'Your password is wron'*/
return ('Your password is wrong!');
};
};
?>

And there you have it... Compleatly created by my own...

Use it wise... May the force be with you :P
Cheers


Last edited by Guest on Tue Dec 12, 2006 8:24 pm, edited 2 times in total.

Report this post
Top
  
Reply with quote  
 Post subject: Good Code
PostPosted: Tue Dec 12, 2006 6:42 pm 

Points:
Wow, that has to be the most advanced script anyone else has ever submitted to this site. Plus you speak very good English so it is easy to follow you. So cool, I'll try it sometime. 8)

The only thing is - do you think you could add a commented version of the code so the new PHP coders could follow the logic? :wink:

Also, you might look at these hashes using md5():

Quote:
The following method, is about 3x faster than md5('apple');
[php]$hash = bin2hex( md5('apple', true) ) ;[/php]


Quote:
This is just something I made while looking into MD5 and SHA-1, how they can be exploited, and whatnot.

[php] /**
* crypto - Generates a hash made up of 40 letters and digits
* by passing a source variable through a custom algorithm.
* First it determines the CRC32, customizable crypt, and MD5
* hashes for the source variable, and implodes them into one
* string. This string can be seperated by another customizable
* salt variable. Finally the SHA-1 hash of the original source
* variable is calculated, with the imploded string appended
* to the end of the source variable.
*/
function crypto($source){
$salt[0] = "something here!"; // Limit this to 16 characters
$salt[1] = "abcd"; // Limit this to 8 characters
$crypt[0] = crc32($source);
$crypt[1] = crypt($source, $salt[0]);
$crypt[2] = md5($source);
$crypt = implode($salt[1], $crypt);
return sha1($source.$crypt);
}[/php]

It works really well if you need a secure, custom hashing function. I hope it works for whatever you use it for!






Quote:
I made this simple script to beat MD5 crackers and it worked, so have fun. Its simple and effective.

[php]<?php
$pass = str_split("mypassword");
foreach ($pass as $hashpass) {
$majorsalt .= md5($hashpass);
}
$corehash = md5($majorsalt);
echo $corehash;
?>[/php]

Tested against rednoise and gdata md5 crackers.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Tue Dec 12, 2006 7:52 pm 

Points:
Yeah, but the problem with that is that you can't get it back to normal again... But I found out a weekness about this script and I'm about to correct it... I'm just going to copy somthing from my own forum, there you can folow how it is built... here it goes:

Ok, so I've created five functions witch we are going to use today, but first I want to tell you about functions... Functions are just peases of code witch does things for us... A function might for exampel be mysql_select_db() witch we used in ouer last tutorial. And to create own functions all you have to do is write [php]function functionName($opptionalFunctionValue1,$opptionalFunctionValue2,$opptionalFunctionValueN){

};[/php]
Also inside a function there is a command named [php]return[/php]. Now basicly what that does is to return a value to wherever it is called... So when i say mysql_numrows($result) it returns the number of rows in $result...

No lets start with todays task. The encoder... The first function i had to write were realy simpel... It is named getAlfabet() and has no values to itselves... It just looks like this [php]function getAlfabet(){
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?,.:;' ".'"';
}[/php]
Now if anyone can't understand what this does, pleas read what i wrote before the
Quote:
[php]return[/php]
, now if you can't understand it after that... Ask you mom :knob: :twisted: ...

Ok, so lets get started on ouer next function...
The myEncrypt($string) function:

[php]function myEncrypt($string){
$alfa = str_split(getAlfabet());
/*Now I only got the alfabet and stored it in an array.
What str_split is that it takes every letter and puts it in an array
Lets have a look at the output of that*/
print_r($alfa)
};
/*Lets not forget to call the function... Function don't do anything until they're called*/
myEncrypt('');[/php]
Messy, huh? Well, it's supose 2 be :twisted: ... But lets continue on ouer function...
Lets remove the print_r function and continue where we left:[php]function myEncrypt($string){
$alfa = str_split(getAlfabet());
/*Now I only got the alfabet and stored it in an array.
What str_split is that it takes every letter and puts it in an array
Now we want to do the same thing with what we are going to encrypt*/
$text = str_split($string);
/*Ok, so now we can start the encrypting... The encrypting mode I am going to use looks like this: '243|aoJkoKn928L?10?!!mmm'. The meaning of that is: 'P4fZ4g3ExDhHwFHGG222' whitch doesn't make any sence but I just wrote somehting... :P... But first we need to find that number whitch is going to stand in front of the code (in this case 243). To do that we just use a random function... So lets get to coding*/
$add = rand(0,1000);
/*How simple was that? We just pick a number between 0 and 1000... Any1 better understand that... Now we need to start making a for loop, but first we need to find out how many rows (letters) there are in the $text varialble*/
$num = count($text);
$nom = count($alfa);
/*Now this for loop is going to be preaty advanced... So you just hang in there... I'll try to comment as much as possible*/
for ($i=0;$i<$num;$i++){
/*Now we need to check if it is equal to any of the letters in $alfa*/
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
$thisNum += $add;
/*Remember that $add was the number we picked*/
while ($thisNum >= 0){
$thisNum -= $nom;
/*Making number less than 0 keping it's bounds to the alfabet after the while I'm adding on the value of $nom to make shure that every number is between 0 and $nom*/
};
$thisNum += $nom;
$allNums .= "$thisNum|";
};
};
};
/*No lets have a break and echo ouer output, shal we?*/
echo($allNums);
};
myEncrypt('test');[/php]
Now, this gives us a nice little output, doesn't it? Actualy this could be the encoded stuff, but there is only one problem... It is not possible to get it back to original text so lets continue...
[php]function myEncrypt($string){
$alfa = str_split(getAlfabet());
/*Now I only got the alfabet and stored it in an array.
What str_split is that it takes every letter and puts it in an array
Now we want to do the same thing with what we are going to encrypt*/
$text = str_split($string);
/*Ok, so now we can start the encrypting... The encrypting mode I am going to use looks like this: '243|aoJkoKn928L?10?!!mmm'. The meaning of that is: 'P4fZ4g3ExDhHwFHGG222' whitch doesn't make any sence but I just wrote somehting... :P... But first we need to find that number whitch is going to stand in front of the code (in this case 243). To do that we just use a random function... So lets get to coding*/
$add = rand(0,1000);
/*How simple was that? We just pick a number between 0 and 1000... Any1 better understand that... Now we need to start making a for loop, but first we need to find out how many rows (letters) there are in the $text varialble*/
$num = count($text);
$nom = count($alfa);
/*Now this for loop is going to be preaty advanced... So you just hang in there... I'll try to comment as much as possible*/
for ($i=0;$i<$num;$i++){
/*Now we need to check if it is equal to any of the letters in $alfa*/
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
$thisNum += $add;
/*Remember that $add was the number we picked*/
while ($thisNum >= 0){
$thisNum -= $nom;
/*Making number less than 0 keping it's bounds to the alfabet after the while I'm adding on the value of $nom to make shure that every number is between 0 and $nom*/
};
$thisNum += $nom;
$allNums .= "$thisNum|";
};
};
};
/*Putting all the numbers inside an array*/
$encr = explode('|',$allNums,-1);
$encrypted = "$add|";
foreach ($encr as $key){
$encrypted .= $alfa[$key];
};
/*And finaly returning the encrypted text!*/
return ($encrypted);
};
echo (myEncrypt('test'));[/php]

Now thats it for the encryption part, hers the code without comments: [php]function myEncrypt($string){
$alfa = str_split(getAlfabet());
$text = str_split($string);
$add = rand(0,1000);
$num = count($text);
$nom = count($alfa);
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
$thisNum += $add;
while ($thisNum >= 0){
$thisNum -= $nom;
};
$thisNum += $nom;
$allNums .= "$thisNum|";
};
};
};
$encr = explode('|',$allNums,-1);
$encrypted = "$add|";
foreach ($encr as $key){
$encrypted .= $alfa[$key];
};
return ($encrypted);
}; [/php]

Now over to the function were we want to add the password...
We now need to create a new function, but this is going to be a lot easier than the other one... You just stick in there...

[php]function passEncrypt($pass,$mess){
$password = myEncrypt($pass);
$passArr = explode('|',$password);
$passNum = $passArr[0];
$passText = $passArr[1];
$message = myEncrypt($mess);
$messArr = explode('|',$message);
$messNum = $messArr[0];
$messText = $messArr[1];
while ($messNum != $passNum){
$message = myEncrypt($mess);
$messArr = explode('|',$message);
$messNum = $messArr[0];
$messText = $messArr[1];
};
$encr = "$passNum|$passText|$messText";
return ($encr);
};[/php]

I hope I'll be able to write the dekode soon... Cheers!

Update: I've made some updates to make the script better... First of all the passEncrypt has been changed: [php]function passEncrypt($pass,$mess){
$password = myEncrypt($pass);
$passArr = explode('|',$password);
$passNum = $passArr[0];
$passText = $passArr[1];
$message = myEncrypt($mess,$passNum);
$messArr = explode('|',$message);
$messNum = $messArr[0];
$messText = $messArr[1];
while ($messNum != $passNum){
$message = myEncrypt($mess);
$messArr = explode('|',$message);
$messNum = $messArr[0];
$messText = $messArr[1];
};
$encr = "$passNum|$passText|$messText";
return ($encr);
};[/php].
Than I've changed the myEncrypt to: [php]function myEncrypt($string,$add = -1){
if ($add == -1){
$add = rand(0,1000);
};
$alfa = str_split(getAlfabet());
$text = str_split($string);
$num = count($text);
$nom = count($alfa);
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
$thisNum += $add;
while ($thisNum >= 0){
$thisNum -= $nom;
};
$thisNum += $nom;
$allNums .= "$thisNum|";
};
};
};
$encr = explode('|',$allNums,-1);
$encrypted = "$add|";
foreach ($encr as $key){
$encrypted .= $alfa[$key];
};
return ($encrypted);
}; [/php] Try figuring out the difference... It isn't that hard...

But as said... This is not yet done, and it is upgraded... This is much more secure! (But yet you can't get this back eather :twisted:


Part 2: OK, here is part two of the version two of the script... The decryption...
Ok guyes... Time to start the decoding... So let just get started...[php] function myDecode($string,$add){
$alfa = str_split(getAlfabet());
/*Getting the alfabet*/
$text = str_split($string);
/*Splitting the string up to an array to get every letter by it self*/
$nom = count($alfa);
$num = count($text);
/*Counting alfa and text*/
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
/*Checking to se if the letter maches any of the letters in $alfa
and if it does giving it the value of $b witch is were we are
looking in $alfa right now*/
$thisNum -= $add;
/*Substracting the value of $add from $thisNum witch is
corresponding to witch letter it is. This is to get it
back to were it was before we encoded it*/
while ($thisNum < 0){
$thisNum += $nom;
/*Making shure that the number is between 0 and $nom*/
};
$allNums .= $alfa[$thisNum];
/*Adding the corresponding letter to $allNums*/
};
};
};
return ($allNums);
/*Returning the $allNums*/
};
/*End of function :-)*/[/php]
This was the myDecode... Now we only need a passDecode... That will look like this: [php] function passDecode($decoded,$pass){
$array = explode('|',$decoded);
/*Sepparating the decoded stuff into an array*/
$add = $array[0];
$encrPass = $array[1];
$encrMess = $array[2];
/*Putting all the three fields inside their own variable*/
$backPass = myDecode($encrPass,$add);
/*Decrypting the password givven in the array*/
$backMess = myDecode($encrMess,$add);
/*Decrypting the message givven in the array*/
if ($pass == $backPass){
return "$backMess";
/*if the password given in the functions parrameters
is right, return the message*/
} else {
return "Wrong Password";
/*Else return wrong password*/
};
};
/*End of function*/[/php]...


And here it is without comments:[php] function myDecode($string,$add){
$alfa = str_split(getAlfabet());
$text = str_split($string);
$nom = count($alfa);
$num = count($text);
for ($i=0;$i<$num;$i++){
for ($b=0;$b<$nom;$b++){
if ($text[$i] == $alfa[$b]){
$thisNum = $b;
$thisNum -= $add;
while ($thisNum < 0){
$thisNum += $nom;
};
$allNums .= $alfa[$thisNum];
};
};
};
return ($allNums);
};
function passDecode($decoded,$pass){
$array = explode('|',$decoded);
$add = $array[0];
$encrPass = $array[1];
$encrMess = $array[2];
$backPass = myDecode($encrPass,$add);
$backMess = myDecode($encrMess,$add);
if ($pass == $backPass){
return "$backMess";
} else {
return "Wrong Password";
};
};[/php]


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]