Skip to content

Instantly share code, notes, and snippets.

@heapbytes
Last active November 21, 2021 16:58
Show Gist options
  • Save heapbytes/81f648c19ec846834fefee5f2c40114a to your computer and use it in GitHub Desktop.
Save heapbytes/81f648c19ec846834fefee5f2c40114a to your computer and use it in GitHub Desktop.
AthackCTF Crypto challenge

Challenge Files:

Script

def my_function(x):
    return pow(x,3)+10*pow(x,2)+x*7 + 6

plaintext = "<censored>"

cipher = []
for i in plaintext : 
   cipher.append(my_function(ord(i)))
print("cipher = " ,cipher)

Output

cipher =  [317336, 1696274, 425598, 1007448, 1069008, 1340288, 346128, 663858, 392496, 2013024, 734808, 1233758, 1268616, 1069008, 1233758, 948296, 142008, 1653936, 948296, 516368, 133974, 1612308, 1133024, 948296, 392496, 1739328, 1452776, 948296, 641264, 133974, 497274, 1783104, 1268616, 1452776, 1199544, 948296, 1531158, 133974, 1377114, 1918824, 1452776, 133974, 1414608, 1268616, 1007448, 1377114, 1653936, 948296, 556008, 619188, 948296, 1037924, 619188, 1739328, 1696274, 1133024, 392496, 133974, 1612308, 1069008, 1268616, 1452776, 1199544, 290184, 47064, 2110256]

Solution

  • So the line return pow(x,3)+10*pow(x,2)+x*7 + 6 takes a char from plaintext and performs some maths to encode the character
  • Each character goes in for loop
    •  for i in plaintext : 
           cipher.append(my_function(ord(i)))
    • As each character of the flag goes inside the function, let's make a variable that has every possible character the flag will have
    •  plaintext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}_1234567890!@#$%^&*()"

Solve.py

def my(x):
    return pow(x,3)+10*pow(x,2)+x*7 + 6

plaintext = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ{}_1234567890!@#$%^&*()"

cipher = [317336, 1696274, 425598, 1007448, 1069008, 1340288, 346128, 663858, 392496, 2013024, 734808, 1233758, 1268616, 1069008, 1233758, 948296, 142008, 1653936, 948296, 516368, 133974, 1612308, 1133024, 948296, 392496, 1739328, 1452776, 948296, 641264, 133974, 497274, 1783104, 1268616, 1452776, 1199544, 948296, 1531158, 133974, 1377114, 1918824, 1452776, 133974, 1414608, 1268616, 1007448, 1377114, 1653936, 948296, 556008, 619188, 948296, 1037924, 619188, 1739328, 1696274, 1133024, 392496, 133974, 1612308, 1069008, 1268616, 1452776, 1199544, 290184, 47064, 2110256]

for i in cipher:
   for j in plaintext:
	if my(ord(j)) == i:
	   print(j,end='')

#flag : AtHackCTF{Which_1s_M0re_Fun_S0Lving_p0lyn0mials_OR_bRuteF0rcing!}  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment