Last active
December 31, 2015 08:39
-
-
Save achudars/7961902 to your computer and use it in GitHub Desktop.
decryption of rainbow encryption ( created by @abradbury )
WARNING! The code might eat up all your RAM
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 itertools | |
import binascii | |
# R - red | |
# O - orange | |
# Y - yellow | |
# G - green | |
# B - blue | |
# I - indigo | |
# V - violet | |
# W - white | |
# an array of all rainbox colours + white | |
LETTERS = ["R","O","Y","G","B","I","V","W"] | |
# string to decode | |
RAINBOW = "WOWWWWWRWYGWWVWWWGBWWWWYWBIWROWGWWVWWWWWWVRWYWWIWROYWWIVWWYWWWWWWYGWWWROWGBWVROYWBIWROYGWIVWOYWW" | |
# list of possible decodings | |
ENCODINGS = ["001","010","011","100","101","110","111","0"] | |
# list of lists of all permutations of encodings | |
PERMUTATIONS_OF_ENCODINGS = list(itertools.permutations(ENCODINGS)) | |
# THE ALGORITHM | |
# iterate over each binary string of each permutation of encoding | |
# substitute each letter with the binary string | |
# convert the resulting binary string to ASCII | |
for bin_list in PERMUTATIONS_OF_ENCODINGS: | |
for bin_string in bin_list: | |
t = RAINBOW | |
for letter in LETTERS: | |
t = t.replace( letter, bin_string) | |
if len(t) % 8 == 0 : | |
print ''.join(chr(int(t[i:i+8], 2)) for i in xrange(0, len(t), 8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment