Created
June 24, 2025 02:34
-
-
Save trycf/8fadd5b41d47a9ed47b3d1468203b085 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains hidden or 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
<cffunction name="encryptcfmx_compat" access="public" returntype="string" output="true"> | |
<cfargument name="input" type="string" required="true"> | |
<cfargument name="key" type="string" required="true"> | |
<cfargument name="alg" type="string" > | |
<cfargument name="format" type="string" > | |
<!--- Inisialisasi LFSR dan konstanta bit ---> | |
<cfset lfsr_a = inputBaseN("13579bdf", 16)> | |
<cfset lfsr_b = inputBaseN("2468ace0", 16)> | |
<cfset lfsr_c = inputBaseN("fdb97531", 16)> | |
<cfset mask_a = inputBaseN("80000062", 16)> | |
<cfset mask_b = inputBaseN("40000020", 16)> | |
<cfset mask_c = inputBaseN("10000002", 16)> | |
<cfset rot0_a = inputBaseN("7fffffff", 16)> | |
<cfset rot0_b = inputBaseN("3fffffff", 16)> | |
<cfset rot0_c = inputBaseN("0fffffff", 16)> | |
<cfset rot1_a = inputBaseN("80000000", 16)> | |
<cfset rot1_b = inputBaseN("c0000000", 16)> | |
<cfset rot1_c = inputBaseN("f0000000", 16)> | |
<!--- Atur key ---> | |
<cfif len(arguments.key) EQ 0> | |
<cfset arguments.key = "Default Seed"> | |
</cfif> | |
<cfset seed = []> | |
<cfloop from="1" to="#len(arguments.key)#" index="i"> | |
<cfset arrayAppend(seed, asc(mid(arguments.key, i, 1)))> | |
</cfloop> | |
<cfloop condition="arrayLen(seed) LT 12"> | |
<cfset arrayAppend(seed, seed[arrayLen(seed) - 11 + arrayLen(seed)])> | |
</cfloop> | |
<!--- Terapkan seed ke LFSR ---> | |
<cfloop from="5" to="8" index="i"> | |
<cfset lfsr_a = bitOr(bitSHLN(lfsr_a, 8), seed[i])> | |
<cfset lfsr_b = bitOr(bitSHLN(lfsr_b, 8), seed[i])> | |
<cfset lfsr_c = bitOr(bitSHLN(lfsr_c, 8), seed[i])> | |
</cfloop> | |
<cfif lfsr_a EQ 0><cfset lfsr_a = inputBaseN("13579bdf", 16)></cfif> | |
<cfif lfsr_b EQ 0><cfset lfsr_b = inputBaseN("2468ace0", 16)></cfif> | |
<cfif lfsr_c EQ 0><cfset lfsr_c = inputBaseN("fdb97531", 16)></cfif> | |
<cfset result = ""> | |
<!--- Loop tiap karakter input ---> | |
<cfloop from="1" to="#len(arguments.input)#" index="i"> | |
<cfset charByte = asc(mid(arguments.input, i, 1))> | |
<cfset crypto = 0> | |
<cfset b = bitAnd(lfsr_b, 1)> | |
<cfset c = bitAnd(lfsr_c, 1)> | |
<cfloop from="1" to="8" index="bit"> | |
<cfif bitAnd(lfsr_a, 1)> | |
<cfset lfsr_a = bitOr(bitXor(bitSHRN(lfsr_a, 1), bitSHRN(mask_a, 1)), rot1_a)> | |
<cfif bitAnd(lfsr_b, 1)> | |
<cfset lfsr_b = bitOr(bitXor(bitSHRN(lfsr_b, 1), bitSHRN(mask_b, 1)), rot1_b)> | |
<cfset b = 1> | |
<cfelse> | |
<cfset lfsr_b = bitAnd(bitSHRN(lfsr_b, 1), rot0_b)> | |
<cfset b = 0> | |
</cfif> | |
<cfelse> | |
<cfset lfsr_a = bitAnd(bitSHRN(lfsr_a, 1), rot0_a)> | |
<cfif bitAnd(lfsr_c, 1)> | |
<cfset lfsr_c = bitOr(bitXor(bitSHRN(lfsr_c, 1), bitSHRN(mask_c, 1)), rot1_c)> | |
<cfset c = 1> | |
<cfelse> | |
<cfset lfsr_c = bitAnd(bitSHRN(lfsr_c, 1), rot0_c)> | |
<cfset c = 0> | |
</cfif> | |
</cfif> | |
<cfset crypto = bitOr(bitSHLN(crypto, 1), bitXor(b, c))> | |
</cfloop> | |
<cfset encryptedByte = bitXor(charByte, crypto)> | |
<cfset result = result & lcase(right("0" & formatBaseN(encryptedByte, 16), 2))> | |
</cfloop> | |
<cfset var byteArray = binaryDecode(result, "hex")> | |
<cfif lcase(arguments.format) EQ "base64"> | |
<cfreturn toBase64(byteArray)> | |
<cfelse> | |
<cfreturn result> | |
</cfif> | |
</cffunction> | |
<cfset encrypted = encryptcfmx_compat("myPassword", "myKey")> | |
<cfoutput>Encrypted = #encrypted#<br></cfoutput> | |
<cfset encrypted2 = encrypt("myPassword", "myKey","CFMX_COMPAT","Hex")> | |
<cfoutput>Encrypted = #encrypted2#<br></cfoutput> | |
<cfset encrypted = encryptcfmx_compat("myPassword", "myKey","","Base64")> | |
<cfoutput>Encrypted_b64 = #encrypted#<br></cfoutput> | |
<cfset encrypted2 = encrypt("myPassword", "myKey","CFMX_COMPAT","Base64")> | |
<cfoutput>Encrypted_b64 = #encrypted2#<br></cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment