リバーシブルテキスト暗号化-ダブルスクエアメソッド

こんにちは

一度、テキストを暗号化する必要がありました。 PHPにはmcrypt拡張機能があることは知っていましたが、私の直感では、これがすべてのホスティングサービスに含まれているわけではないと示唆しました。
したがって、私は自分で解決策をコーディングする必要があると疑い始めました。 私が実際にしたこと。 結果は、十分に高速で信頼性の高い可逆暗号化機能です。
関数の例:
 <?php 
	 echo dsCrypt( 'habrahabr.ru');
	 //印刷:60634K7T0 * 0!
	 echo dsCrypt( '60634K7T0 * 0!'、1);
	 //印刷:habrahabr.ru
 ?>

それでもXOR暗号化を使用している場合:)、カットの下を見て、他にデータを保護する方法を確認できます...

驚いたことに、インターネットをさまよう後、PHPには既製のソリューションはほとんどないことがわかりました。
Caesarの暗号化実装、さまざまなワイルドカード、そしてみんなのお気に入りのXORを見つけました。 より深刻で永続的なものは見つかりませんでした。
それから、私はかなり単純で、合理的に強力な(私の仕事のための)Double Square暗号化方法を思い出しました。
彼について聞いたことがない人のために、彼はかなり強力なコードを提供し、いくつかの特別なサービスが第二次世界大戦中にそれを使用したとしか言えません。
もちろん、最新のキップアナリストまたは頭のあるプログラマーは、十分な量のソースと暗号化されたテキストを手に持って、しばらく時間を費やしてからそれを開くことができます。
したがって、重要な企業または個人の機密情報を隠すために使用しないでください。
「先駆者」、ボット、および一般ユーザーから情報を隠す必要がありました。したがって、私の要件では、頭で十分な強度がありました。
その結果、1つの関数にDouble Squareアルゴリズムを実装しました。

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 ); }


必要な人はすべて使用しますが、許容範囲内でのみ使用してください。

ところで、私は喜んで批判に耳を傾け、可逆暗号化の他のシンプルで信頼できる方法の実装を見ていきます。 mcryptを提供しないでください)

がんばって。

Update1:​​同様の機能を使用して、たとえばボットからメールを隠します。

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


All Articles