fiher

Untitled

Jun 2nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.14 KB | None | 0 0
  1. <?php
  2. $text = trim(fgets(STDIN));
  3. $secretKey= "42KDJ2D!$#!@KDI@D";
  4. $key = "pesho";
  5. $privateKey = "pesho";
  6. function cipher0($text){
  7. $textLength = strlen($text);
  8. $splitInto = 0;
  9. $textAsArray = [];
  10. $anythingLeft = false;
  11. if($textLength>=5 && $textLength < 10){$splitInto = 2;}
  12. elseif ($textLength<15){$splitInto = 4;}
  13. elseif ($textLength<20){$splitInto = 8;}
  14. elseif ($textLength<30){$splitInto = 6;}
  15. elseif ($textLength<35){$splitInto = 10;}
  16. elseif ($textLength<45){$splitInto = 8;}
  17. elseif ($textLength<50){$splitInto = 4;}
  18. elseif ($textLength<60){$splitInto = 12;}
  19. elseif ($textLength<70){$splitInto = 14;}
  20. elseif ($textLength<80){$splitInto = 16;}
  21. elseif ($textLength<90){$splitInto = 12;}
  22. elseif ($textLength<100){$splitInto = 8;}
  23. elseif ($textLength<120){$splitInto = 14;}
  24. elseif ($textLength<150){$splitInto = 18;}
  25. elseif ($textLength<160){$splitInto = 14;}
  26. elseif ($textLength<180){$splitInto = 16;}
  27. elseif ($textLength<190){$splitInto = 8;}
  28. elseif ($textLength<200){$splitInto = 4;}
  29. elseif ($textLength<240){$splitInto = 9;}
  30. elseif ($textLength<280){$splitInto = 21;}
  31. elseif ($textLength<290){$splitInto = 32;}
  32. elseif ($textLength<300){$splitInto = 14;}
  33. elseif ($textLength<320){$splitInto = 35;}
  34. elseif ($textLength<340){$splitInto = 21;}
  35. elseif ($textLength<356){$splitInto = 4;}
  36. elseif ($textLength<456){$splitInto = 2;}
  37. elseif ($textLength<500){$splitInto = 5;}
  38. elseif ($textLength<550){$splitInto = 23;}
  39. elseif ($textLength>=550){$splitInto = 40;}
  40. $arrayOfTextBlocks = [];
  41. $leftBlockOfText = "";
  42. $index = 0;
  43. $text = implode("",array_reverse(str_split($text)));
  44. for($i= 0 ; $i<$splitInto;$i++){
  45. $textBlock = "";
  46. for ($y = 0;$y<floor($textLength/$splitInto);$y++){
  47. $textBlock .= $text[$index];
  48. $index++;
  49. }
  50. $arrayOfTextBlocks[] = $textBlock;
  51. }
  52.  
  53. $arrayOfTextBlocks = array_reverse($arrayOfTextBlocks);
  54. foreach ($arrayOfTextBlocks as $textBlock){
  55. $textAsArray[] = $textBlock;
  56. }
  57. if($index<$textLength){
  58. for ($i = $index;$i<$textLength;$i++){
  59. $leftBlockOfText .= $text[$i];
  60. }
  61. $textAsArray[] = $leftBlockOfText;
  62. }
  63.  
  64. return implode("",$textAsArray);
  65. }
  66. function cipher1($text,$key,$privateKey,$secretKey){
  67. $textLegnth = strlen($text);
  68. $insertIndex = floor($textLegnth/3);
  69. $text = strrev($text);
  70. $textAsArray = str_split($text);
  71.  
  72. for ($i = 0; $i < strlen($key); $i++) {
  73. array_splice($textAsArray, $insertIndex+$i, 0, $key[$i]);
  74. }
  75. for ($i = 0; $i < strlen($privateKey); $i++) {
  76. array_splice($textAsArray, $insertIndex*2+$i, 0, $privateKey[$i]);
  77. }
  78. for ($i = 0; $i < strlen($secretKey); $i++) {
  79. array_splice($textAsArray, $insertIndex*3+$i, 0, $secretKey[$i]);
  80. }
  81. $text = implode("",$textAsArray);
  82. $text = strrev($text);
  83.  
  84. return $text;
  85. }
  86. function cipher2($text,$key,$privateKey,$isFirst){
  87. $textLength = strlen($text);
  88. $cipheredText = [];
  89. $isOdd = false;
  90. $counter = $textLength/2;
  91. if(!is_int($counter)) {
  92. $counter = floor($counter);
  93. $isOdd = true;
  94. }
  95. for($i = 0; $i<$counter;$i++){
  96. $cipheredText[] = $text[$textLength-1-$i];
  97. $cipheredText[] = $text[$i];
  98. }
  99. if($isFirst) {
  100. for ($i = 0; $i < strlen($key); $i++) {
  101. array_splice($cipheredText, 2, 0, $key[$i]);
  102. }
  103. for ($i = 0; $i < strlen($privateKey); $i++) {
  104. array_splice($cipheredText, 3, 0, $privateKey[$i]);
  105. }
  106. }
  107. if($isOdd){
  108. $cipheredText[] = $text[intval($counter)];
  109. }
  110. return implode("",$cipheredText);
  111. }
  112. function cipher3($text){
  113. $shift = array( "4"=>"z","2"=>"f","8"=>"s","1"=>"r","9"=>"k",
  114. "6"=>"w","0"=>"t","3"=>";","5"=>"@","7"=>"*","A"=>"b",
  115. "x"=>"y","t"=>"8","R"=>"4","Q"=>"d","@"=>"$","c"=>"l","!"=>"c","i"=>"G",
  116. "("=>"D","#"=>"#","e"=>"e","h"=>"h","n"=>"q","a"=>"g","b"=>"F",
  117. "C"=>"<","F"=>"g","o"=>"n","%"=>"B","&"=>"3","j"=>"x","_"=>"9",
  118. "H"=>"J","q"=>"i","k"=>"^","J"=>"0","d"=>"a","u"=>"j","l"=>"v",")"=>"+",
  119. "y"=>"5","E"=>"2","D"=>"o","f"=>"1","p"=>"!","L"=>"L","$"=>"%",
  120. "w"=>"E","m"=>"m","N"=>"(","G"=>"A","I"=>"H","T"=>"P","K"=>"7","M"=>"I",
  121. "O"=>"K","P"=>"M","S"=>"N","U"=>"?","V"=>"&","*"=>"Q","W"=>"O",
  122. "X"=>"R","Y"=>"p","Z"=>")","r"=>"S","s"=>"T","|"=>"u","?"=>"|","\""=>"6",
  123. "^"=>">","+"=>"Z","v"=>"U","z"=>"_","<"=>"V",">"=>"W",";"=>"X","B"=>"Y"
  124. );
  125. for ($i=0;$i<count($text);$i+=1){
  126. if (key_exists($text[$i],$shift)){
  127. $textAsArray[$i] = $shift[$text[$i]];
  128. }
  129. }
  130. return $text;
  131. }
  132. function cipher4($text){
  133. $textLength = strlen($text);
  134. for ($i = 0; $i < $textLength; $i++){
  135. $asciiChange = $i+1;
  136. if($asciiChange >27){
  137. $asciiChange = $asciiChange %27;
  138. }
  139. $letterASCII = ord($text[$i]);
  140. $letterASCII += $asciiChange;
  141. $text[$i] = chr($letterASCII);
  142. }
  143. return $text;
  144. }
  145. function cipher5($text){
  146.  
  147. }
  148. function decipher0($text){
  149. $textLength = strlen($text);
  150. $splitInto = 0;
  151. $textAsArray = [];
  152. $anythingLeft = false;
  153. if($textLength>=5 && $textLength < 10){$splitInto = 2;}
  154. elseif ($textLength<15){$splitInto = 4;}
  155. elseif ($textLength<20){$splitInto = 8;}
  156. elseif ($textLength<30){$splitInto = 6;}
  157. elseif ($textLength<35){$splitInto = 10;}
  158. elseif ($textLength<45){$splitInto = 8;}
  159. elseif ($textLength<50){$splitInto = 4;}
  160. elseif ($textLength<60){$splitInto = 12;}
  161. elseif ($textLength<70){$splitInto = 14;}
  162. elseif ($textLength<80){$splitInto = 16;}
  163. elseif ($textLength<90){$splitInto = 12;}
  164. elseif ($textLength<100){$splitInto = 8;}
  165. elseif ($textLength<120){$splitInto = 14;}
  166. elseif ($textLength<150){$splitInto = 18;}
  167. elseif ($textLength<160){$splitInto = 14;}
  168. elseif ($textLength<180){$splitInto = 16;}
  169. elseif ($textLength<190){$splitInto = 8;}
  170. elseif ($textLength<200){$splitInto = 4;}
  171. elseif ($textLength<240){$splitInto = 9;}
  172. elseif ($textLength<280){$splitInto = 21;}
  173. elseif ($textLength<290){$splitInto = 32;}
  174. elseif ($textLength<300){$splitInto = 14;}
  175. elseif ($textLength<320){$splitInto = 35;}
  176. elseif ($textLength<340){$splitInto = 21;}
  177. elseif ($textLength<356){$splitInto = 4;}
  178. elseif ($textLength<456){$splitInto = 2;}
  179. elseif ($textLength<500){$splitInto = 5;}
  180. elseif ($textLength<550){$splitInto = 23;}
  181. elseif ($textLength>=550){$splitInto = 40;}
  182. $arrayOfTextBlocks = [];
  183. $leftBlockOfText = "";
  184. $index = 0;
  185. for($i= 0 ; $i<$splitInto;$i++){
  186. $textBlock = "";
  187. for ($y = 0;$y<floor($textLength/$splitInto);$y++){
  188. $textBlock .= $text[$index];
  189. $index++;
  190. }
  191. $arrayOfTextBlocks[] = $textBlock;
  192. }
  193. $arrayOfTextBlocks = array_reverse($arrayOfTextBlocks);
  194. foreach ($arrayOfTextBlocks as $textBlock){
  195. $textAsArray[] = $textBlock;
  196. }
  197.  
  198. if($index<$textLength){
  199. for ($i = $index;$i<$textLength;$i++){
  200. $leftBlockOfText .= $text[$i];
  201. }
  202. $textAsArray[] = $leftBlockOfText;
  203. }
  204. return strrev(implode("",$textAsArray));
  205. }
  206. function decipher1($text, $key, $privateKey,$secretKey){
  207. $textLength = strlen($text);
  208. $text = strrev($text);
  209. $textAsArray = str_split($text);
  210. $keyLength = strlen($key);
  211. $privateKeyLength = strlen($privateKey);
  212. $secretKeyLength = strlen($secretKey);
  213. $actualTextLength = $textLength - $keyLength - $privateKeyLength - $secretKeyLength;
  214. $insertIndex = floor($actualTextLength/3);
  215. for ($i = 0; $i < strlen($secretKey); $i++) {
  216. unset($textAsArray[intval($insertIndex*3+$i)]);
  217. }$textAsArray = array_values($textAsArray);
  218. for ($i = 0; $i < strlen($privateKey); $i++) {
  219. unset($textAsArray[intval($insertIndex*2+$i)]);
  220. }$textAsArray = array_values($textAsArray);
  221. for ($i = 0; $i < strlen($key); $i++) {
  222. unset($textAsArray[intval($insertIndex+$i)]);
  223. } $textAsArray = array_values($textAsArray);
  224. $text = strrev(implode("",$textAsArray));
  225.  
  226. return $text;
  227. }
  228. function decipher2($text,$key,$privateKey,$isFirst){
  229. list( $insertPositionKey, $insertPositionPrivateKey, $textAsArray) = array( 2, 3, str_split($text));
  230. if($isFirst) {
  231. for ($i = 0; $i < strlen($privateKey); $i++) {
  232. unset($textAsArray[$insertPositionPrivateKey]);
  233. $textAsArray = array_values($textAsArray);
  234. }
  235. for ($i = 0; $i < strlen($key); $i++) {
  236. unset($textAsArray[$insertPositionKey]);
  237. $textAsArray = array_values($textAsArray);
  238. }
  239. }
  240. $cypheredText = implode("",$textAsArray);
  241. $textLength = strlen($cypheredText);
  242. $isOdd = false;
  243. $counter = $textLength/2;
  244. if(!is_int($counter)) {
  245. $counter = floor($counter);
  246. $isOdd = true;
  247. }
  248. $decypherText = $array = array_fill(0,$textLength, "0");
  249. $decypherText[count($decypherText)-1] = $cypheredText[0];
  250. $decypherText[0] = $cypheredText[1];
  251.  
  252. $odd = 0;
  253. $shift = 0;
  254.  
  255. if($isOdd){
  256. $decypherText[$counter] = $cypheredText[$textLength-1];
  257. $odd = 1;
  258. }else{
  259. $shift = 1;
  260. }
  261. $insertPosition = 1;
  262. for($i = 2; $i<$textLength-1-$odd;$i+=2){
  263. $num = count($decypherText)-1-$odd-$shift;
  264. $decypherText[count($decypherText)-1-$odd-$shift] = $cypheredText[$i];
  265. $decypherText[$insertPosition] = $cypheredText[$i+1];
  266.  
  267. $shift+=1;
  268. $insertPosition+=1;
  269. }
  270. return implode("",$decypherText);
  271.  
  272. }
  273. function decipher3($text){
  274. $shift = array_flip($shift = array( "4"=>"z","2"=>"f","8"=>"s","1"=>"r","9"=>"k",
  275. "6"=>"w","0"=>"t","3"=>";","5"=>"@","7"=>"*","A"=>"b",
  276. "x"=>"y","t"=>"8","R"=>"4","Q"=>"d","@"=>"$","c"=>"l","!"=>"c","i"=>"G",
  277. "("=>"D","#"=>"#","e"=>"e","h"=>"h","n"=>"q","a"=>"g","b"=>"F",
  278. "C"=>"<","F"=>"g","o"=>"n","%"=>"B","&"=>"3","j"=>"x","_"=>"9",
  279. "H"=>"J","q"=>"i","k"=>"^","J"=>"0","d"=>"a","u"=>"j","l"=>"v",")"=>"+",
  280. "y"=>"5","E"=>"2","D"=>"o","f"=>"1","p"=>"!","L"=>"L","$"=>"%",
  281. "w"=>"E","m"=>"m","N"=>"(","G"=>"A","I"=>"H","T"=>"P","K"=>"7","M"=>"I",
  282. "O"=>"K","P"=>"M","S"=>"N","U"=>"?","V"=>"&","*"=>"Q","W"=>"O",
  283. "X"=>"R","Y"=>"p","Z"=>")","r"=>"S","s"=>"T","|"=>"u","?"=>"|","\""=>"6",
  284. "^"=>">","+"=>"Z","v"=>"U","z"=>"_","<"=>"V",">"=>"W",";"=>"X","B"=>"Y"
  285. ));
  286. for ($i=0;$i<count($text);$i+=1){
  287. if (key_exists($text[$i],$shift)){
  288. $textAsArray[$i] = $shift[$text[$i]];
  289. }
  290. }
  291. return $text;
  292. }
  293. function decipher4($text){
  294. $textLength = strlen($text);
  295. for ($i = 0; $i < $textLength; $i++){
  296. $asciiChange = $i+1;
  297. if($asciiChange >27){
  298. $asciiChange = $asciiChange %27;
  299. }
  300. $letterASCII = ord($text[$i]);
  301. $letterASCII -= $asciiChange;
  302. $text[$i] = chr($letterASCII);
  303. }
  304. return $text;
  305. }
  306. for($i = 0 ;$i<1000;$i++){
  307. $text = cipher0($text);
  308. }
  309. for($i = 0 ;$i<50;$i++){
  310. $text = cipher1($text,$key,$privateKey,$secretKey);
  311. }
  312. for($i = 0 ; $i<50;$i++){
  313. $isFirst = false;
  314. if($i ==0){
  315. $isFirst = true;
  316. }
  317. $text = cipher2($text,$key,$privateKey,$isFirst);
  318. }
  319. for($i = 0; $i<50; $i++){
  320. $text = cipher3($text);
  321. $text = cipher0($text);
  322. }
  323. for($i = 0 ;$i<50;$i++){
  324. $text = cipher4($text);
  325. }
  326. echo "encrypted text is - > ".$text.PHP_EOL;
  327. for($i = 0 ;$i<50;$i++){
  328. $text = decipher4($text);
  329. }
  330. for($i = 0; $i<50; $i++){
  331. $text = decipher3($text);
  332. $text = decipher0($text);
  333. }
  334. for($i = 0 ; $i<50;$i++){
  335. $isFirst = false;
  336. if($i ==49){
  337. $isFirst = true;
  338. }
  339. $text = decipher2($text,$key,$privateKey,$isFirst);
  340. }
  341. for($i = 0 ;$i<50;$i++){
  342. $text = decipher1($text,$key,$privateKey,$secretKey);
  343. }
  344. for($i = 0 ;$i<1000;$i++){
  345. $text = decipher0($text);
  346. }
  347. echo " original text was - > ".$text.PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment