Created
August 29, 2012 17:35
-
-
Save libbkmz/3515980 to your computer and use it in GitHub Desktop.
crypt and decrypt to bitmask
This file contains hidden or 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
string = "abcdefabcdeabcddcbacdbacdbbabdcfbcdabfbcdf" | |
result = [] | |
mask = 0 | |
rules = { | |
1: "a", | |
2: "b", | |
4: "c", | |
8: "d", | |
16: "e", | |
32: "f", | |
} | |
# removing duples in string | |
string = "".join(set([x for x in string])) | |
# adding bitmask for strings | |
for i,vl in iter(reversed(sorted(rules.iteritems()))): | |
if vl in string: | |
mask += i | |
while mask > 0: | |
for i,vl in iter(reversed(sorted(rules.iteritems()))): | |
if mask - i >= 0: | |
mask -= i | |
result.append(vl) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment