Last active
November 14, 2017 02:04
-
-
Save paced/db40aea55881d5de0607a4ba2282ac62 to your computer and use it in GitHub Desktop.
Cracking a specific known cipher method (not shown) by reverse engineering.
This file contains 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
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