Page 1 of 1

Crack This

Posted: Mon Jun 25, 2007 8:46 pm
by pcmattman
Try this one out if you're bored...

Decode this string:

Code: Select all

s1f24~Z]l8qgm8<MH8qgm8[Yf?l8j]Y\8l`ak8kljaf_8g^8l]plFFF
Python program to encrypt/decrypt strings will be posted once I'm happy with your attempts, it's really not that hard. I'll give hints out every now and then as well.

Hint 1: this is encrypted with a factor of 24 and a strength of 1.

Have fun :D

Posted: Tue Jun 26, 2007 12:40 am
by ucosty
I got

[NfBET YOU $50 YOU CAN'T READ THIS STRING OF TEXT...

But it doesn't look entirely decoded.

Posted: Tue Jun 26, 2007 12:50 am
by pcmattman
Well done... Sort of.

You've decoded the English part but you're also trying to decode something that isn't the encoded string.
Hint 1: this is encrypted with a factor of 24 and a strength of 1.
s1f24 :D

The ~ means that the actual string is starting.

The Python script to do this:

Code: Select all

import sys,string,random

str_to_encrypt = ""
str_to_decrypt = ""
strength = 1
factor = 32

# find arguments
for i in range( 0, len( sys.argv ) ):
	if( sys.argv[i] == "-e" ):
		str_to_encrypt = sys.argv[i+1]
		i = i + 1
	if( sys.argv[i] == "-d" ):
		str_to_decrypt = sys.argv[i+1]
		i = i + 1
	if( sys.argv[i] == "-s" ):
		strength = int( sys.argv[i+1] )
		i = i + 1
	if( sys.argv[i] == "-f" ):
		if( sys.argv[i+1] == "?rand?" ):
			factor = random.randint( 16, pow( 2, 32 ) )
		else:
			factor = int( sys.argv[i+1] )
		i = i + 1

# final results
final_encrypted_str = ""
final_decrypted_str = ""

# and then do encryption
if( str_to_encrypt != "" ):
	
	# everything automatically changes to caps
	str_to_encrypt = string.upper( str_to_encrypt )

	# store the strength and factor
	final_encrypted_str += "s" + str( strength )
	final_encrypted_str += "f" + str( factor )
	final_encrypted_str += "~"

	# change every letter
	for i in range( 0, len( str_to_encrypt ) ):

		# check for overflow
		if( ( ord( str_to_encrypt[i] ) + (strength * factor) ) > 255 ):
			final_encrypted_str += "_r" + str( ( ord( str_to_encrypt[i] ) + (strength * factor) ) / 255 ) + "_"
			final_encrypted_str += chr( ( ord( str_to_encrypt[i] ) + (strength * factor) ) % 255 )
		else:
			final_encrypted_str += chr( ord( str_to_encrypt[i] ) + (strength * factor) )

# tell me
print final_encrypted_str

# do we need to decrypt?
if( str_to_decrypt != "" ):

	# index variable
	i = 0; s = 0; e = 0;

	# check for special case
	if( str_to_decrypt == "?enc?" and str_to_encrypt != "" ):
		str_to_decrypt = final_encrypted_str

	# everything will automatically be in the right case, so find our sig
	while( 1 ):
		if( str_to_decrypt[i] == 's' ):
			s = i + 1
		if( str_to_decrypt[i] == 'f' ):
			e = i - 1
			str_strength = ""
			for j in range( s, e + 1 ):
				str_strength += str_to_decrypt[j]
			strength = int( str_strength )
			s = i + 1
		if( str_to_decrypt[i] == '~' ):
			e = i - 1
			str_factor = ""
			for j in range( s, e + 1 ):
				str_factor += str_to_decrypt[j]
			factor = int( str_factor )
			break
		i = i + 1

	# the end of the signature, we're about to destroy i
	sigend = i + 1

	# now, decrypt each character
	i = sigend
	while( 1 ):

		# check for tell-tale patterns
		if( str_to_decrypt[i] == '_' and str_to_decrypt[i+1] == 'r' ):

			# handle the exceeding number...

			# count of times this goes into 255
			count = 0

			# offset
			start = i + 2

			# change i accordingly
			i = start

			# loop, until the last _ is found
			while( True ):

				if( str_to_decrypt[i] == '_' ):

					# temp string for the count
					str_count = ""

					# done, get the count
					for j in range( start, i ):
						str_count += str_to_decrypt[j]

					# convert it
					count = int( str_count )

					# one more for i
					i = i + 1

					# we're done here
					break

				i = i + 1

			# and now finally add the proper character to the list
			final_decrypted_str += chr( ( ord( str_to_decrypt[i] ) - (strength*factor) ) % (255) )
			
		else:
			final_decrypted_str += chr( ord( str_to_decrypt[i] ) - (strength*factor) )

		# one more for i
		i = i + 1

		# check for valid i
		if( i >= len( str_to_decrypt ) ):
			break

# tell me
print final_decrypted_str
PM me if you want C code - the C version is more efficient and doesn't worry about the overflow (it makes sure no overflow can occur by restricting the factor/strength pair).

Any ideas/comments you guys want to throw in would be appreciated.

Posted: Tue Jun 26, 2007 12:55 am
by ucosty
This is what I decoded it with, a few simple lines of php code:

Code: Select all

$inputstring = 's1f24~Z]l8qgm8<MH8qgm8[Yf?l8j]Y\8l`ak8kljaf_8g^8l]plFFF';

$test = ord('8') - ord(' ');
$inputarray = str_split($inputstring);

foreach($inputarray as $c)
{
	echo chr(ord($c) - $test );
}
I ran the input through a simple script to find the most common letters, and the number 8 stood out as a probable space character.

Posted: Tue Jun 26, 2007 12:58 am
by pcmattman
Interesting...

Still, a lot of the code in my script is just special handling for each part of the final string.

Edit: also, a lot of it is because I was hacking away at it without any documentation, and no internet, so I had to hack together the substrings... There has got to be a substr function in Python...