@@ -20,77 +20,65 @@ public static string DecipherWithVersion(string cipher, string cipherVersion)
2020 var funcBody = Regex . Match ( js , funcPattern ) . Groups [ "brace" ] . Value ; //Entire sig function
2121 var lines = funcBody . Split ( ';' ) ; //Each line in sig function
2222
23- string id_Reverse = "" , id_Slice = "" , id_CharSwap = "" ; //Hold name for each cipher method
23+ string idReverse = "" , idSlice = "" , idCharSwap = "" ; //Hold name for each cipher method
2424 string functionIdentifier = "" ;
2525 string operations = "" ;
2626
27-
28- foreach ( var line in lines . Skip ( 1 ) . Take ( lines . Length - 2 ) ) //Matchs the funcBody with each cipher method. Only runs till all three are defined.
27+ foreach ( var line in lines . Skip ( 1 ) . Take ( lines . Length - 2 ) ) //Matches the funcBody with each cipher method. Only runs till all three are defined.
2928 {
30- if ( ! string . IsNullOrEmpty ( id_Reverse ) && ! string . IsNullOrEmpty ( id_Slice ) &&
31- ! string . IsNullOrEmpty ( id_CharSwap ) )
32- {
29+ if ( ! string . IsNullOrEmpty ( idReverse ) && ! string . IsNullOrEmpty ( idSlice ) &&
30+ ! string . IsNullOrEmpty ( idCharSwap ) )
31+ {
3332 break ; //Break loop if all three cipher methods are defined
34- }
33+ }
3534
36- functionIdentifier = getFunctionFromLine ( line ) ;
37- string re_Reverse = string . Format ( @"{0}:\bfunction\b\(\w+\)" , functionIdentifier ) ; //Regex for reverse (one parameter)
38- string re_Slice = string . Format ( @"{0}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\." , functionIdentifier ) ; //Regex for slice (return or not)
39- string re_Swap = string . Format ( @"{0}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b" , functionIdentifier ) ; //Regex for the char swap.
35+ functionIdentifier = GetFunctionFromLine ( line ) ;
36+ string reReverse = string . Format ( @"{0}:\bfunction\b\(\w+\)" , functionIdentifier ) ; //Regex for reverse (one parameter)
37+ string reSlice = string . Format ( @"{0}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\." , functionIdentifier ) ; //Regex for slice (return or not)
38+ string reSwap = string . Format ( @"{0}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b" , functionIdentifier ) ; //Regex for the char swap.
4039
41- Match me ;
42- if ( ( me = Regex . Match ( js , re_Reverse ) ) . Success )
40+ if ( Regex . Match ( js , reReverse ) . Success )
4341 {
44- id_Reverse = functionIdentifier ; //If def matched the regex for reverse then the current function is a defined as the reverse
45- }
42+ idReverse = functionIdentifier ; //If def matched the regex for reverse then the current function is a defined as the reverse
43+ }
4644
47- if ( ( me = Regex . Match ( js , re_Slice ) ) . Success )
45+ if ( Regex . Match ( js , reSlice ) . Success )
4846 {
49- id_Slice = functionIdentifier ; //If def matched the regex for slice then the current function is defined as the slice.
50- }
51-
52- if ( ( me = Regex . Match ( js , re_Swap ) ) . Success )
53- {
54- id_CharSwap = functionIdentifier ; //If def matched the regex for charSwap then the current function is defined as swap.
55- }
47+ idSlice = functionIdentifier ; //If def matched the regex for slice then the current function is defined as the slice.
48+ }
5649
50+ if ( Regex . Match ( js , reSwap ) . Success )
51+ {
52+ idCharSwap = functionIdentifier ; //If def matched the regex for charSwap then the current function is defined as swap.
53+ }
5754 }
5855
5956 foreach ( var line in lines . Skip ( 1 ) . Take ( lines . Length - 2 ) )
6057 {
6158 Match m ;
62- functionIdentifier = getFunctionFromLine ( line ) ;
59+ functionIdentifier = GetFunctionFromLine ( line ) ;
6360
64- if ( ( m = Regex . Match ( line , @"\(\w+,(?<index>\d+)\)" ) ) . Success && functionIdentifier == id_CharSwap )
65- {
61+ if ( ( m = Regex . Match ( line , @"\(\w+,(?<index>\d+)\)" ) ) . Success && functionIdentifier == idCharSwap )
62+ {
6663 operations += "w" + m . Groups [ "index" ] . Value + " " ; //operation is a swap (w)
67- }
64+ }
6865
69- if ( ( m = Regex . Match ( line , @"\(\w+,(?<index>\d+)\)" ) ) . Success && functionIdentifier == id_Slice )
70- {
66+ if ( ( m = Regex . Match ( line , @"\(\w+,(?<index>\d+)\)" ) ) . Success && functionIdentifier == idSlice )
67+ {
7168 operations += "s" + m . Groups [ "index" ] . Value + " " ; //operation is a slice
72- }
69+ }
7370
74- if ( functionIdentifier == id_Reverse ) //No regex required for reverse (reverse method has no parameters)
75- {
71+ if ( functionIdentifier == idReverse ) //No regex required for reverse (reverse method has no parameters)
72+ {
7673 operations += "r " ; //operation is a reverse
7774 }
78-
7975 }
8076
8177 operations = operations . Trim ( ) ;
8278
8379 return DecipherWithOperations ( cipher , operations ) ;
8480 }
8581
86- private static string getFunctionFromLine ( string currentLine )
87- {
88- Regex matchFunctionReg = new Regex ( @"\w+\.(?<functionID>\w+)\(" ) ; //lc.ac(b,c) want the ac part.
89- Match rgMatch = matchFunctionReg . Match ( currentLine ) ;
90- string matchedFunction = rgMatch . Groups [ "functionID" ] . Value ;
91- return matchedFunction ; //return 'ac'
92- }
93-
9482 private static string ApplyOperation ( string cipher , string op )
9583 {
9684 switch ( op [ 0 ] )
@@ -121,6 +109,14 @@ private static string DecipherWithOperations(string cipher, string operations)
121109 . Aggregate ( cipher , ApplyOperation ) ;
122110 }
123111
112+ private static string GetFunctionFromLine ( string currentLine )
113+ {
114+ Regex matchFunctionReg = new Regex ( @"\w+\.(?<functionID>\w+)\(" ) ; //lc.ac(b,c) want the ac part.
115+ Match rgMatch = matchFunctionReg . Match ( currentLine ) ;
116+ string matchedFunction = rgMatch . Groups [ "functionID" ] . Value ;
117+ return matchedFunction ; //return 'ac'
118+ }
119+
124120 private static int GetOpIndex ( string op )
125121 {
126122 string parsed = new Regex ( @".(\d+)" ) . Match ( op ) . Result ( "$1" ) ;
0 commit comments