📜 ⬆️ ⬇️

Reversible Text Encryption - Dual Square Method

Hello!

Once, I needed to encrypt the text. I knew that in PHP there is an extension mcrypt, but intuition suggested that not all hosts are enabled.
Therefore, I began to suspect that I would have to code the decision myself. What I actually did. It turned out the function of reversible encryption, fast enough and reliable.
Example of the function:
 <? php 
	 echo dsCrypt ('habrahabr.ru');
	 // Displays: 60634K7T0 * 0!
	 echo dsCrypt ('60634K7T0 * 0!', 1);
	 // Displays: habrahabr.ru
 ?>

If you are still using XOR encryption :), then you can look under the cat and see how you can still protect the data ...

After wandering on an Internet, I was surprised to find that there was practically no ready-made PHP solution.
I found Caesar's encryption implementations, Various substitutions, and everyone's favorite XOR. More serious and persistent could not be found.
Then I remembered a fairly simple and sufficiently strong (for my task) encryption method "Double Square".
For those who have not heard about him, I will only say that he gives a sufficiently strong cipher, and some special services used it during the Second World War.
Of course, a modern type analyst or programmer with a head will be able to open it after spending some time, having a sufficient amount of source and encrypted text in hand.
Therefore, do not use it to conceal important corporate or personal confidential information.
I had to hide information from "pioneers", bots and ordinary users, therefore, under my requirements of perseverance, I had enough of my head.
As a result, I implemented the “Double Square” algorithm in one function.

Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  1. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  2. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  3. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  4. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  5. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  6. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  7. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  8. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  9. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  10. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  11. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  12. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  13. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  14. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  15. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  16. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  17. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  18. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  19. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  20. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  21. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  22. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  23. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  24. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  25. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  26. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  27. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  28. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  29. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  30. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  31. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  32. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  33. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  34. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  35. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  36. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  37. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  38. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  39. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  40. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  41. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  42. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  43. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  44. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  45. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  46. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }
  47. Copy Source | Copy HTML /** <br/> * " " (Reversible crypting of "Double square" method) <br/> * @param String $input <br/> * @param bool $decrypt <br/> * @return String | <br/> * @author runcore <br/> */ function dsCrypt( $input , $decrypt = false ) { $o = $s1 = $s2 = array (); // Arrays for: Output, Square1, Square2 // $basea = array ( '?' , '(' , '@' , ';' , '$' , '#' , "]" , "&" , '*' ); // base symbol set $basea = array_merge( $basea , range( 'a' , 'z' ), range( 'A' , 'Z' ), range(0, 9 ) ); $basea = array_merge( $basea , array ( '!' , ')' , '_' , '+' , '|' , '%' , '/' , '[' , '.' , ' ' ) ); $dimension = 9 ; // of squares for ( $i =0; $i < $dimension ; $i ++) { // create Squares for ( $j =0; $j < $dimension ; $j ++) { $s1 [ $i ][ $j ] = $basea [ $i * $dimension + $j ]; $s2 [ $i ][ $j ] = str_rot13( $basea [( $dimension * $dimension - 1 ) - ( $i * $dimension + $j )]); } } unset ( $basea ); $m = floor(strlen( $input )/ 2 )* 2 ; // !strlen%2 $symbl = $m ==strlen( $input ) ? '' : $input [strlen( $input )- 1 ]; // last symbol (unpaired) $al = array (); // crypt/uncrypt pairs of symbols for ( $ii =0; $ii < $m ; $ii += 2 ) { $symb1 = $symbn1 = strval( $input [ $ii ]); $symb2 = $symbn2 = strval( $input [ $ii + 1 ]); $a1 = $a2 = array (); for ( $i =0; $i < $dimension ; $i ++) { // search symbols in Squares for ( $j =0; $j < $dimension ; $j ++) { if ( $decrypt ) { if ( $symb1 ===strval( $s2 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s1 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s2 [ $i ][ $j ])) $al = array ( $i , $j ); } else { if ( $symb1 ===strval( $s1 [ $i ][ $j ]) ) $a1 = array ( $i , $j ); if ( $symb2 ===strval( $s2 [ $i ][ $j ]) ) $a2 = array ( $i , $j ); if (! empty ( $symbl ) && $symbl ===strval( $s1 [ $i ][ $j ])) $al = array ( $i , $j ); } } } if (sizeof( $a1 ) && sizeof( $a2 )) { $symbn1 = $decrypt ? $s1 [ $a1 [0]][ $a2 [ 1 ]] : $s2 [ $a1 [0]][ $a2 [ 1 ]]; $symbn2 = $decrypt ? $s2 [ $a2 [0]][ $a1 [ 1 ]] : $s1 [ $a2 [0]][ $a1 [ 1 ]]; } $o [] = $symbn1 . $symbn2 ; } if (! empty ( $symbl ) && sizeof( $al )) // last symbol $o [] = $decrypt ? $s1 [ $al [ 1 ]][$al[0]] : $s2 [ $al [ 1 ]][ $al [0]]; return implode( '' , $o ); }

')
Use everyone who wants, but use it with your head, only where it is permissible.

By the way, I’m happy to hear criticism and look at the implementation of other simple and reliable methods of reversible encryption. mcrypt not to offer)

Good luck.

Update1: I use a similar function to hide Emails from bots, for example.

Source: https://habr.com/ru/post/61309/


All Articles