Skip to content

Instantly share code, notes, and snippets.

@paced
Last active November 14, 2017 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paced/db40aea55881d5de0607a4ba2282ac62 to your computer and use it in GitHub Desktop.
Save paced/db40aea55881d5de0607a4ba2282ac62 to your computer and use it in GitHub Desktop.
Cracking a specific known cipher method (not shown) by reverse engineering.
import random, string
random.seed("random")
secret = "BNZQ:8o149b15764q471k2533971t6w78liec"
decoded = ""
# Each line will definitely remain lower/upper/digit.
# To find out why, pay attention to the origin code.
for i in secret:
if i.islower():
stage0 = (ord(i) - ord('a')) # range should now be 0 to 25.
stage1 = (stage0 - random.randrange(0, 26))%26
stage2 = (stage1 + ord('a'))
decoded += chr(stage2)
elif i.isupper():
stage0 = (ord(i) - ord('A')) # range should now be 0 to 25.
stage1 = (stage0 - random.randrange(0, 26))%26
stage2 = (stage1 + ord('A'))
decoded += chr(stage2)
elif i.isdigit():
stage0 = (ord(i) - ord('0')) # range should now be 0 to 25.
stage1 = (stage0 - random.randrange(0, 10))%10
stage2 = (stage1 + ord('0'))
decoded += chr(stage2)
else:
decoded += i
print "Decoded flag: " + decoded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment