Last active
December 14, 2017 10:16
-
-
Save marinsagovac/5d805b135ca1270a0a68 to your computer and use it in GitHub Desktop.
Grim string to number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$num_to_char = array( | |
'27' => "1", | |
'28' => "2", | |
'29' => "3", | |
'30' => "4", | |
'31' => "5", | |
'32' => "6", | |
'33' => "7", | |
'34' => "8", | |
'35' => "9", | |
'36' => "0", | |
'1' => "a", | |
'2' => "b", | |
'3' => "c", | |
'4' => "d", | |
'5' => "e", | |
'6' => "f", | |
'7' => "g", | |
'8' => "h", | |
'9' => "i", | |
'10' => "j", | |
'11' => "k", | |
'12' => "l", | |
'13' => "m", | |
'14' => "n", | |
'15' => "o", | |
'16' => "p", | |
'17' => "q", | |
'18' => "r", | |
'19' => "s", | |
'20' => "t", | |
'21' => "u", | |
'22' => "v", | |
'23' => "w", | |
'24' => "x", | |
'25' => "y", | |
'26' => "z", | |
'37' => "A", | |
'38' => "B", | |
'39' => "C", | |
'40' => "D", | |
'41' => "E", | |
'42' => "F", | |
'43' => "G", | |
'44' => "H", | |
'45' => "I", | |
'46' => "J", | |
'47' => "K", | |
'48' => "L", | |
'49' => "M", | |
'50' => "N", | |
'51' => "O", | |
'52' => "P", | |
'53' => "Q", | |
'54' => "R", | |
'55' => "S", | |
'56' => "T", | |
'57' => "U", | |
'58' => "V", | |
'59' => "W", | |
'60' => "X", | |
'61' => "Y", | |
'62' => "Z", | |
'63' => "!", | |
'64' => "\"", | |
'65' => "�", | |
'66' => "\$", | |
'67' => "^", | |
'68' => "&", | |
'69' => "*", | |
'70' => "(", | |
'71' => ")", | |
'72' => "_", | |
'73' => "+", | |
'74' => "-", | |
'75' => "=", | |
'76' => "`", | |
'77' => ",", | |
'78' => ".", | |
'79' => "/", | |
'80' => "<", | |
'81' => ">", | |
'82' => "?", | |
'83' => ";", | |
'84' => "'", | |
'85' => "#", | |
'86' => ":", | |
'87' => "@", | |
'88' => "~", | |
'89' => "[", | |
'90' => "]", | |
'91' => "{", | |
'92' => "}", | |
'93' => " ", | |
'94' => "%", | |
); | |
$char_to_num = array( | |
'a' => 1, | |
'b' => 2, | |
'c' => 3, | |
'd' => 4, | |
'e' => 5, | |
'f' => 6, | |
'g' => 7, | |
'h' => 8, | |
'i' => 9, | |
'j' => 10, | |
'k' => 11, | |
'l' => 12, | |
'm' => 13, | |
'n' => 14, | |
'o' => 15, | |
'p' => 16, | |
'q' => 17, | |
'r' => 18, | |
's' => 19, | |
't' => 20, | |
'u' => 21, | |
'v' => 22, | |
'w' => 23, | |
'x' => 24, | |
'y' => 25, | |
'z' => 26, | |
'1' => 27, | |
'2' => 28, | |
'3' => 29, | |
'4' => 30, | |
'5' => 31, | |
'6' => 32, | |
'7' => 33, | |
'8' => 34, | |
'9' => 35, | |
'0' => 36, | |
'A' => 37, | |
'B' => 38, | |
'C' => 39, | |
'D' => 40, | |
'E' => 41, | |
'F' => 42, | |
'G' => 43, | |
'H' => 44, | |
'I' => 45, | |
'J' => 46, | |
'K' => 47, | |
'L' => 48, | |
'M' => 49, | |
'N' => 50, | |
'O' => 51, | |
'P' => 52, | |
'Q' => 53, | |
'R' => 54, | |
'S' => 55, | |
'T' => 56, | |
'U' => 57, | |
'V' => 58, | |
'W' => 59, | |
'X' => 60, | |
'Y' => 61, | |
'Z' => 62, | |
'!' => 63, | |
'\"' => 64, | |
'�' => 65, | |
'\$' => 66, | |
'^' => 67, | |
'&' => 68, | |
'*' => 69, | |
'(' => 70, | |
')' => 71, | |
'_' => 72, | |
'+' => 73, | |
'-' => 74, | |
'=' => 75, | |
'`' => 76, | |
',' => 77, | |
'.' => 78, | |
'/' => 79, | |
'<' => 80, | |
'>' => 81, | |
'?' => 82, | |
';' => 83, | |
'\'' => 84, | |
'#' => 85, | |
':' => 86, | |
'@' => 87, | |
'~' => 88, | |
'[' => 89, | |
']' => 90, | |
'{' => 91, | |
'}' => 92, | |
' ' => 93, | |
'%' => 94, | |
); | |
function lookup($char){ | |
global $num_to_char; | |
return $num_to_char[$char]; | |
} | |
function grimstring_to_nums($string){ | |
$nums = array(); | |
$c = 0; | |
$total = 0; | |
$len = strlen($string); | |
while ($c < $len){ | |
$a = substr($string, $c, 1); | |
$num = substr($string, $c+1, $a); | |
$nums[] = $num; | |
$total += $num; | |
$c += $a+1; | |
} | |
$total = $total / (count($nums) + 1); | |
$out = array(); | |
foreach($nums as $num){ | |
$out[] = $num - $total; | |
} | |
return $out; | |
} | |
function crack_gcrypt($input){ | |
return implode('', array_map("lookup", grimstring_to_nums($input))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment